bump product version to 6.3.0.0.beta1
[LibreOffice.git] / connectivity / source / drivers / ado / AResultSetMetaData.cxx
blob23983342ebc54c75beaa338aeec1d4a17cc5cf82
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 <ado/AResultSetMetaData.hxx>
21 #include <com/sun/star/sdbc/DataType.hpp>
22 #include <com/sun/star/sdbc/ColumnValue.hpp>
23 #include <ado/Awrapado.hxx>
24 #include <connectivity/dbexception.hxx>
26 using namespace connectivity;
27 using namespace connectivity::ado;
28 using namespace com::sun::star::uno;
29 using namespace com::sun::star::lang;
30 using namespace com::sun::star::beans;
31 using namespace com::sun::star::sdbc;
33 OResultSetMetaData::OResultSetMetaData( ADORecordset* _pRecordSet)
34 : m_pRecordSet(_pRecordSet),
35 m_nColCount(-1)
37 if ( m_pRecordSet )
38 m_pRecordSet->AddRef();
41 OResultSetMetaData::~OResultSetMetaData()
43 if ( m_pRecordSet )
44 m_pRecordSet->Release();
47 sal_Int32 SAL_CALL OResultSetMetaData::getColumnDisplaySize( sal_Int32 column )
49 WpADOField aField = ADOS::getField(m_pRecordSet,column);
50 if(aField.IsValid() && aField.GetActualSize() != -1)
51 return aField.GetActualSize();
52 return 0;
56 sal_Int32 SAL_CALL OResultSetMetaData::getColumnType( sal_Int32 column )
58 WpADOField aField = ADOS::getField(m_pRecordSet,column);
59 return ADOS::MapADOType2Jdbc(aField.GetADOType());
63 sal_Int32 SAL_CALL OResultSetMetaData::getColumnCount( )
65 if(m_nColCount != -1 )
66 return m_nColCount;
68 if ( !m_pRecordSet )
69 return 0;
71 ADOFields* pFields = nullptr;
72 m_pRecordSet->get_Fields(&pFields);
73 WpOLEAppendCollection<ADOFields, ADOField, WpADOField> aFields(pFields);
74 m_nColCount = aFields.GetItemCount();
75 return m_nColCount;
79 sal_Bool SAL_CALL OResultSetMetaData::isCaseSensitive( sal_Int32 column )
81 bool bRet = false;
82 WpADOField aField = ADOS::getField(m_pRecordSet,column);
83 if ( aField.IsValid() )
85 WpADOProperties aProps( aField.get_Properties() );
86 if ( aProps.IsValid() )
87 bRet = OTools::getValue( aProps, OUString("ISCASESENSITIVE") ).getBool();
89 return bRet;
93 OUString SAL_CALL OResultSetMetaData::getSchemaName( sal_Int32 /*column*/ )
95 return OUString();
99 OUString SAL_CALL OResultSetMetaData::getColumnName( sal_Int32 column )
101 WpADOField aField = ADOS::getField(m_pRecordSet,column);
102 if(aField.IsValid())
103 return aField.GetName();
105 return OUString();
108 OUString SAL_CALL OResultSetMetaData::getTableName( sal_Int32 column )
110 OUString sTableName;
112 WpADOField aField = ADOS::getField(m_pRecordSet,column);
113 if ( aField.IsValid() )
115 WpADOProperties aProps( aField.get_Properties() );
116 if ( aProps.IsValid() )
117 sTableName = OTools::getValue( aProps, OUString("BASETABLENAME") ).getString();
119 return sTableName;
122 OUString SAL_CALL OResultSetMetaData::getCatalogName( sal_Int32 /*column*/ )
124 return OUString();
127 OUString SAL_CALL OResultSetMetaData::getColumnTypeName( sal_Int32 /*column*/ )
129 return OUString();
132 OUString SAL_CALL OResultSetMetaData::getColumnLabel( sal_Int32 column )
134 return getColumnName(column);
137 OUString SAL_CALL OResultSetMetaData::getColumnServiceName( sal_Int32 /*column*/ )
139 return OUString();
143 sal_Bool SAL_CALL OResultSetMetaData::isCurrency( sal_Int32 column )
145 WpADOField aField = ADOS::getField(m_pRecordSet,column);
146 if(aField.IsValid())
148 return ((aField.GetAttributes() & adFldFixed) == adFldFixed) && (aField.GetADOType() == adCurrency);
150 return false;
154 sal_Bool SAL_CALL OResultSetMetaData::isAutoIncrement( sal_Int32 column )
156 bool bRet = false;
157 WpADOField aField = ADOS::getField(m_pRecordSet,column);
158 if ( aField.IsValid() )
160 WpADOProperties aProps( aField.get_Properties() );
161 if ( aProps.IsValid() )
163 bRet = OTools::getValue( aProps, OUString("ISAUTOINCREMENT") ).getBool();
166 return bRet;
170 sal_Bool SAL_CALL OResultSetMetaData::isSigned( sal_Int32 column )
172 WpADOField aField = ADOS::getField(m_pRecordSet,column);
173 if(aField.IsValid())
175 DataTypeEnum eType = aField.GetADOType();
176 return !(eType == adUnsignedBigInt || eType == adUnsignedInt || eType == adUnsignedSmallInt || eType == adUnsignedTinyInt);
178 return false;
181 sal_Int32 SAL_CALL OResultSetMetaData::getPrecision( sal_Int32 column )
183 WpADOField aField = ADOS::getField(m_pRecordSet,column);
184 if(aField.IsValid())
185 return aField.GetPrecision();
186 return 0;
189 sal_Int32 SAL_CALL OResultSetMetaData::getScale( sal_Int32 column )
191 WpADOField aField = ADOS::getField(m_pRecordSet,column);
192 if(aField.IsValid())
193 return aField.GetNumericScale();
194 return 0;
198 sal_Int32 SAL_CALL OResultSetMetaData::isNullable( sal_Int32 column )
200 WpADOField aField = ADOS::getField(m_pRecordSet,column);
201 if(aField.IsValid())
203 return sal_Int32((aField.GetAttributes() & adFldIsNullable) == adFldIsNullable);
205 return sal_Int32(false);
209 sal_Bool SAL_CALL OResultSetMetaData::isSearchable( sal_Int32 /*column*/ )
211 return true;
215 sal_Bool SAL_CALL OResultSetMetaData::isReadOnly( sal_Int32 column )
217 WpADOField aField = ADOS::getField(m_pRecordSet,column);
218 if(aField.IsValid())
220 // return (aField.GetStatus() & adFieldReadOnly) == adFieldReadOnly;
222 return false;
226 sal_Bool SAL_CALL OResultSetMetaData::isDefinitelyWritable( sal_Int32 column )
228 WpADOField aField = ADOS::getField(m_pRecordSet,column);
229 if(aField.IsValid())
231 return (aField.GetAttributes() & adFldUpdatable) == adFldUpdatable;
233 return false;
237 sal_Bool SAL_CALL OResultSetMetaData::isWritable( sal_Int32 column )
239 return isDefinitelyWritable(column);
243 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */