1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
),
38 m_pRecordSet
->AddRef();
41 OResultSetMetaData::~OResultSetMetaData()
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();
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 )
71 ADOFields
* pFields
= nullptr;
72 m_pRecordSet
->get_Fields(&pFields
);
73 WpOLEAppendCollection
<ADOFields
, ADOField
, WpADOField
> aFields(pFields
);
74 m_nColCount
= aFields
.GetItemCount();
79 sal_Bool SAL_CALL
OResultSetMetaData::isCaseSensitive( sal_Int32 column
)
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();
93 OUString SAL_CALL
OResultSetMetaData::getSchemaName( sal_Int32
/*column*/ )
99 OUString SAL_CALL
OResultSetMetaData::getColumnName( sal_Int32 column
)
101 WpADOField aField
= ADOS::getField(m_pRecordSet
,column
);
103 return aField
.GetName();
108 OUString SAL_CALL
OResultSetMetaData::getTableName( sal_Int32 column
)
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();
122 OUString SAL_CALL
OResultSetMetaData::getCatalogName( sal_Int32
/*column*/ )
127 OUString SAL_CALL
OResultSetMetaData::getColumnTypeName( sal_Int32
/*column*/ )
132 OUString SAL_CALL
OResultSetMetaData::getColumnLabel( sal_Int32 column
)
134 return getColumnName(column
);
137 OUString SAL_CALL
OResultSetMetaData::getColumnServiceName( sal_Int32
/*column*/ )
143 sal_Bool SAL_CALL
OResultSetMetaData::isCurrency( sal_Int32 column
)
145 WpADOField aField
= ADOS::getField(m_pRecordSet
,column
);
148 return ((aField
.GetAttributes() & adFldFixed
) == adFldFixed
) && (aField
.GetADOType() == adCurrency
);
154 sal_Bool SAL_CALL
OResultSetMetaData::isAutoIncrement( sal_Int32 column
)
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();
170 sal_Bool SAL_CALL
OResultSetMetaData::isSigned( sal_Int32 column
)
172 WpADOField aField
= ADOS::getField(m_pRecordSet
,column
);
175 DataTypeEnum eType
= aField
.GetADOType();
176 return !(eType
== adUnsignedBigInt
|| eType
== adUnsignedInt
|| eType
== adUnsignedSmallInt
|| eType
== adUnsignedTinyInt
);
181 sal_Int32 SAL_CALL
OResultSetMetaData::getPrecision( sal_Int32 column
)
183 WpADOField aField
= ADOS::getField(m_pRecordSet
,column
);
185 return aField
.GetPrecision();
189 sal_Int32 SAL_CALL
OResultSetMetaData::getScale( sal_Int32 column
)
191 WpADOField aField
= ADOS::getField(m_pRecordSet
,column
);
193 return aField
.GetNumericScale();
198 sal_Int32 SAL_CALL
OResultSetMetaData::isNullable( sal_Int32 column
)
200 WpADOField aField
= ADOS::getField(m_pRecordSet
,column
);
203 return sal_Int32((aField
.GetAttributes() & adFldIsNullable
) == adFldIsNullable
);
205 return sal_Int32(false);
209 sal_Bool SAL_CALL
OResultSetMetaData::isSearchable( sal_Int32
/*column*/ )
215 sal_Bool SAL_CALL
OResultSetMetaData::isReadOnly( sal_Int32 column
)
217 WpADOField aField
= ADOS::getField(m_pRecordSet
,column
);
220 // return (aField.GetStatus() & adFieldReadOnly) == adFieldReadOnly;
226 sal_Bool SAL_CALL
OResultSetMetaData::isDefinitelyWritable( sal_Int32 column
)
228 WpADOField aField
= ADOS::getField(m_pRecordSet
,column
);
231 return (aField
.GetAttributes() & adFldUpdatable
) == adFldUpdatable
;
237 sal_Bool SAL_CALL
OResultSetMetaData::isWritable( sal_Int32 column
)
239 return isDefinitelyWritable(column
);
243 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */