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 <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
),
42 m_pRecordSet
->AddRef();
45 OResultSetMetaData::~OResultSetMetaData()
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();
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 )
75 WpOLEAppendCollection
<ADOFields
, WpADOField
> pFields
;
76 m_pRecordSet
->get_Fields(&pFields
);
77 m_nColCount
= pFields
.GetItemCount();
82 sal_Bool SAL_CALL
OResultSetMetaData::isCaseSensitive( sal_Int32 column
)
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();
96 OUString SAL_CALL
OResultSetMetaData::getSchemaName( sal_Int32
/*column*/ )
102 OUString SAL_CALL
OResultSetMetaData::getColumnName( sal_Int32 column
)
104 WpADOField aField
= ADOS::getField(m_pRecordSet
,column
);
106 return aField
.GetName();
111 OUString SAL_CALL
OResultSetMetaData::getTableName( sal_Int32 column
)
115 WpADOField aField
= ADOS::getField(m_pRecordSet
,column
);
116 if ( aField
.IsValid() )
118 WpADOProperties
aProps( aField
.get_Properties() );
119 if ( aProps
.IsValid() )
121 = OTools::getValue(aProps
, std::u16string_view(u
"BASETABLENAME")).getString();
126 OUString SAL_CALL
OResultSetMetaData::getCatalogName( sal_Int32
/*column*/ )
131 OUString SAL_CALL
OResultSetMetaData::getColumnTypeName( sal_Int32
/*column*/ )
136 OUString SAL_CALL
OResultSetMetaData::getColumnLabel( sal_Int32 column
)
138 return getColumnName(column
);
141 OUString SAL_CALL
OResultSetMetaData::getColumnServiceName( sal_Int32
/*column*/ )
147 sal_Bool SAL_CALL
OResultSetMetaData::isCurrency( sal_Int32 column
)
149 WpADOField aField
= ADOS::getField(m_pRecordSet
,column
);
152 return ((aField
.GetAttributes() & adFldFixed
) == adFldFixed
) && (aField
.GetADOType() == adCurrency
);
158 sal_Bool SAL_CALL
OResultSetMetaData::isAutoIncrement( sal_Int32 column
)
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();
174 sal_Bool SAL_CALL
OResultSetMetaData::isSigned( sal_Int32 column
)
176 WpADOField aField
= ADOS::getField(m_pRecordSet
,column
);
179 DataTypeEnum eType
= aField
.GetADOType();
180 return !(eType
== adUnsignedBigInt
|| eType
== adUnsignedInt
|| eType
== adUnsignedSmallInt
|| eType
== adUnsignedTinyInt
);
185 sal_Int32 SAL_CALL
OResultSetMetaData::getPrecision( sal_Int32 column
)
187 WpADOField aField
= ADOS::getField(m_pRecordSet
,column
);
189 return aField
.GetPrecision();
193 sal_Int32 SAL_CALL
OResultSetMetaData::getScale( sal_Int32 column
)
195 WpADOField aField
= ADOS::getField(m_pRecordSet
,column
);
197 return aField
.GetNumericScale();
202 sal_Int32 SAL_CALL
OResultSetMetaData::isNullable( sal_Int32 column
)
204 WpADOField aField
= ADOS::getField(m_pRecordSet
,column
);
207 return sal_Int32((aField
.GetAttributes() & adFldIsNullable
) == adFldIsNullable
);
209 return sal_Int32(false);
213 sal_Bool SAL_CALL
OResultSetMetaData::isSearchable( sal_Int32
/*column*/ )
219 sal_Bool SAL_CALL
OResultSetMetaData::isReadOnly( sal_Int32 column
)
221 WpADOField aField
= ADOS::getField(m_pRecordSet
,column
);
224 // return (aField.GetStatus() & adFieldReadOnly) == adFieldReadOnly;
230 sal_Bool SAL_CALL
OResultSetMetaData::isDefinitelyWritable( sal_Int32 column
)
232 WpADOField aField
= ADOS::getField(m_pRecordSet
,column
);
235 return (aField
.GetAttributes() & adFldUpdatable
) == adFldUpdatable
;
241 sal_Bool SAL_CALL
OResultSetMetaData::isWritable( sal_Int32 column
)
243 return isDefinitelyWritable(column
);
247 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */