Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / connectivity / source / drivers / ado / AResultSetMetaData.cxx
blobd43ee5da9216eaecbe153f69eed486c7936d6f35
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <sal/config.h>
22 #include <string_view>
24 #include <ado/AResultSetMetaData.hxx>
25 #include <com/sun/star/sdbc/DataType.hpp>
26 #include <com/sun/star/sdbc/ColumnValue.hpp>
27 #include <ado/Awrapado.hxx>
28 #include <connectivity/dbexception.hxx>
30 using namespace connectivity;
31 using namespace connectivity::ado;
32 using namespace com::sun::star::uno;
33 using namespace com::sun::star::lang;
34 using namespace com::sun::star::beans;
35 using namespace com::sun::star::sdbc;
37 OResultSetMetaData::OResultSetMetaData( ADORecordset* _pRecordSet)
38 : m_pRecordSet(_pRecordSet),
39 m_nColCount(-1)
41 if ( m_pRecordSet )
42 m_pRecordSet->AddRef();
45 OResultSetMetaData::~OResultSetMetaData()
47 if ( m_pRecordSet )
48 m_pRecordSet->Release();
51 sal_Int32 SAL_CALL OResultSetMetaData::getColumnDisplaySize( sal_Int32 column )
53 WpADOField aField = ADOS::getField(m_pRecordSet,column);
54 if(aField.IsValid() && aField.GetActualSize() != -1)
55 return aField.GetActualSize();
56 return 0;
60 sal_Int32 SAL_CALL OResultSetMetaData::getColumnType( sal_Int32 column )
62 WpADOField aField = ADOS::getField(m_pRecordSet,column);
63 return ADOS::MapADOType2Jdbc(aField.GetADOType());
67 sal_Int32 SAL_CALL OResultSetMetaData::getColumnCount( )
69 if(m_nColCount != -1 )
70 return m_nColCount;
72 if ( !m_pRecordSet )
73 return 0;
75 WpOLEAppendCollection<ADOFields, WpADOField> pFields;
76 m_pRecordSet->get_Fields(&pFields);
77 m_nColCount = pFields.GetItemCount();
78 return m_nColCount;
82 sal_Bool SAL_CALL OResultSetMetaData::isCaseSensitive( sal_Int32 column )
84 bool bRet = false;
85 WpADOField aField = ADOS::getField(m_pRecordSet,column);
86 if ( aField.IsValid() )
88 WpADOProperties aProps( aField.get_Properties() );
89 if ( aProps.IsValid() )
90 bRet = OTools::getValue(aProps, std::u16string_view(u"ISCASESENSITIVE")).getBool();
92 return bRet;
96 OUString SAL_CALL OResultSetMetaData::getSchemaName( sal_Int32 /*column*/ )
98 return OUString();
102 OUString SAL_CALL OResultSetMetaData::getColumnName( sal_Int32 column )
104 WpADOField aField = ADOS::getField(m_pRecordSet,column);
105 if(aField.IsValid())
106 return aField.GetName();
108 return OUString();
111 OUString SAL_CALL OResultSetMetaData::getTableName( sal_Int32 column )
113 OUString sTableName;
115 WpADOField aField = ADOS::getField(m_pRecordSet,column);
116 if ( aField.IsValid() )
118 WpADOProperties aProps( aField.get_Properties() );
119 if ( aProps.IsValid() )
120 sTableName
121 = OTools::getValue(aProps, std::u16string_view(u"BASETABLENAME")).getString();
123 return sTableName;
126 OUString SAL_CALL OResultSetMetaData::getCatalogName( sal_Int32 /*column*/ )
128 return OUString();
131 OUString SAL_CALL OResultSetMetaData::getColumnTypeName( sal_Int32 /*column*/ )
133 return OUString();
136 OUString SAL_CALL OResultSetMetaData::getColumnLabel( sal_Int32 column )
138 return getColumnName(column);
141 OUString SAL_CALL OResultSetMetaData::getColumnServiceName( sal_Int32 /*column*/ )
143 return OUString();
147 sal_Bool SAL_CALL OResultSetMetaData::isCurrency( sal_Int32 column )
149 WpADOField aField = ADOS::getField(m_pRecordSet,column);
150 if(aField.IsValid())
152 return ((aField.GetAttributes() & adFldFixed) == adFldFixed) && (aField.GetADOType() == adCurrency);
154 return false;
158 sal_Bool SAL_CALL OResultSetMetaData::isAutoIncrement( sal_Int32 column )
160 bool bRet = false;
161 WpADOField aField = ADOS::getField(m_pRecordSet,column);
162 if ( aField.IsValid() )
164 WpADOProperties aProps( aField.get_Properties() );
165 if ( aProps.IsValid() )
167 bRet = OTools::getValue(aProps, std::u16string_view(u"ISAUTOINCREMENT")).getBool();
170 return bRet;
174 sal_Bool SAL_CALL OResultSetMetaData::isSigned( sal_Int32 column )
176 WpADOField aField = ADOS::getField(m_pRecordSet,column);
177 if(aField.IsValid())
179 DataTypeEnum eType = aField.GetADOType();
180 return !(eType == adUnsignedBigInt || eType == adUnsignedInt || eType == adUnsignedSmallInt || eType == adUnsignedTinyInt);
182 return false;
185 sal_Int32 SAL_CALL OResultSetMetaData::getPrecision( sal_Int32 column )
187 WpADOField aField = ADOS::getField(m_pRecordSet,column);
188 if(aField.IsValid())
189 return aField.GetPrecision();
190 return 0;
193 sal_Int32 SAL_CALL OResultSetMetaData::getScale( sal_Int32 column )
195 WpADOField aField = ADOS::getField(m_pRecordSet,column);
196 if(aField.IsValid())
197 return aField.GetNumericScale();
198 return 0;
202 sal_Int32 SAL_CALL OResultSetMetaData::isNullable( sal_Int32 column )
204 WpADOField aField = ADOS::getField(m_pRecordSet,column);
205 if(aField.IsValid())
207 return sal_Int32((aField.GetAttributes() & adFldIsNullable) == adFldIsNullable);
209 return sal_Int32(false);
213 sal_Bool SAL_CALL OResultSetMetaData::isSearchable( sal_Int32 /*column*/ )
215 return true;
219 sal_Bool SAL_CALL OResultSetMetaData::isReadOnly( sal_Int32 column )
221 WpADOField aField = ADOS::getField(m_pRecordSet,column);
222 if(aField.IsValid())
224 // return (aField.GetStatus() & adFieldReadOnly) == adFieldReadOnly;
226 return false;
230 sal_Bool SAL_CALL OResultSetMetaData::isDefinitelyWritable( sal_Int32 column )
232 WpADOField aField = ADOS::getField(m_pRecordSet,column);
233 if(aField.IsValid())
235 return (aField.GetAttributes() & adFldUpdatable) == adFldUpdatable;
237 return false;
241 sal_Bool SAL_CALL OResultSetMetaData::isWritable( sal_Int32 column )
243 return isDefinitelyWritable(column);
247 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */