LibreOffice Module connectivity (master) 1
AResultSetMetaData.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <sal/config.h>
21
22#include <string_view>
23
25#include <com/sun/star/sdbc/DataType.hpp>
26#include <com/sun/star/sdbc/ColumnValue.hpp>
27#include <ado/Awrapado.hxx>
29
30using namespace connectivity;
31using namespace connectivity::ado;
32using namespace com::sun::star::uno;
33using namespace com::sun::star::lang;
34using namespace com::sun::star::beans;
35using namespace com::sun::star::sdbc;
36
37OResultSetMetaData::OResultSetMetaData( ADORecordset* _pRecordSet)
38 : m_pRecordSet(_pRecordSet),
39 m_nColCount(-1)
40{
41 if ( m_pRecordSet )
42 m_pRecordSet->AddRef();
43}
44
46{
47 if ( m_pRecordSet )
48 m_pRecordSet->Release();
49}
50
51sal_Int32 SAL_CALL OResultSetMetaData::getColumnDisplaySize( sal_Int32 column )
52{
53 WpADOField aField = ADOS::getField(m_pRecordSet,column);
54 if(aField.IsValid() && aField.GetActualSize() != -1)
55 return aField.GetActualSize();
56 return 0;
57}
58
59
60sal_Int32 SAL_CALL OResultSetMetaData::getColumnType( sal_Int32 column )
61{
62 WpADOField aField = ADOS::getField(m_pRecordSet,column);
63 return ADOS::MapADOType2Jdbc(aField.GetADOType());
64}
65
66
68{
69 if(m_nColCount != -1 )
70 return m_nColCount;
71
72 if ( !m_pRecordSet )
73 return 0;
74
76 m_pRecordSet->get_Fields(&pFields);
77 m_nColCount = pFields.GetItemCount();
78 return m_nColCount;
79}
80
81
83{
84 bool bRet = false;
85 WpADOField aField = ADOS::getField(m_pRecordSet,column);
86 if ( aField.IsValid() )
87 {
88 WpADOProperties aProps( aField.get_Properties() );
89 if ( aProps.IsValid() )
90 bRet = OTools::getValue(aProps, std::u16string_view(u"ISCASESENSITIVE")).getBool();
91 }
92 return bRet;
93}
94
95
96OUString SAL_CALL OResultSetMetaData::getSchemaName( sal_Int32 /*column*/ )
97{
98 return OUString();
99}
100
101
102OUString SAL_CALL OResultSetMetaData::getColumnName( sal_Int32 column )
103{
104 WpADOField aField = ADOS::getField(m_pRecordSet,column);
105 if(aField.IsValid())
106 return aField.GetName();
107
108 return OUString();
109}
110
111OUString SAL_CALL OResultSetMetaData::getTableName( sal_Int32 column )
112{
113 OUString sTableName;
114
115 WpADOField aField = ADOS::getField(m_pRecordSet,column);
116 if ( aField.IsValid() )
117 {
118 WpADOProperties aProps( aField.get_Properties() );
119 if ( aProps.IsValid() )
120 sTableName
121 = OTools::getValue(aProps, std::u16string_view(u"BASETABLENAME")).getString();
122 }
123 return sTableName;
124}
125
126OUString SAL_CALL OResultSetMetaData::getCatalogName( sal_Int32 /*column*/ )
127{
128 return OUString();
129}
130
131OUString SAL_CALL OResultSetMetaData::getColumnTypeName( sal_Int32 /*column*/ )
132{
133 return OUString();
134}
135
136OUString SAL_CALL OResultSetMetaData::getColumnLabel( sal_Int32 column )
137{
138 return getColumnName(column);
139}
140
141OUString SAL_CALL OResultSetMetaData::getColumnServiceName( sal_Int32 /*column*/ )
142{
143 return OUString();
144}
145
146
147sal_Bool SAL_CALL OResultSetMetaData::isCurrency( sal_Int32 column )
148{
149 WpADOField aField = ADOS::getField(m_pRecordSet,column);
150 if(aField.IsValid())
151 {
152 return ((aField.GetAttributes() & adFldFixed) == adFldFixed) && (aField.GetADOType() == adCurrency);
153 }
154 return false;
155}
156
157
159{
160 bool bRet = false;
161 WpADOField aField = ADOS::getField(m_pRecordSet,column);
162 if ( aField.IsValid() )
163 {
164 WpADOProperties aProps( aField.get_Properties() );
165 if ( aProps.IsValid() )
166 {
167 bRet = OTools::getValue(aProps, std::u16string_view(u"ISAUTOINCREMENT")).getBool();
168 }
169 }
170 return bRet;
171}
172
173
174sal_Bool SAL_CALL OResultSetMetaData::isSigned( sal_Int32 column )
175{
176 WpADOField aField = ADOS::getField(m_pRecordSet,column);
177 if(aField.IsValid())
178 {
179 DataTypeEnum eType = aField.GetADOType();
180 return !(eType == adUnsignedBigInt || eType == adUnsignedInt || eType == adUnsignedSmallInt || eType == adUnsignedTinyInt);
181 }
182 return false;
183}
184
185sal_Int32 SAL_CALL OResultSetMetaData::getPrecision( sal_Int32 column )
186{
187 WpADOField aField = ADOS::getField(m_pRecordSet,column);
188 if(aField.IsValid())
189 return aField.GetPrecision();
190 return 0;
191}
192
193sal_Int32 SAL_CALL OResultSetMetaData::getScale( sal_Int32 column )
194{
195 WpADOField aField = ADOS::getField(m_pRecordSet,column);
196 if(aField.IsValid())
197 return aField.GetNumericScale();
198 return 0;
199}
200
201
202sal_Int32 SAL_CALL OResultSetMetaData::isNullable( sal_Int32 column )
203{
204 WpADOField aField = ADOS::getField(m_pRecordSet,column);
205 if(aField.IsValid())
206 {
207 return sal_Int32((aField.GetAttributes() & adFldIsNullable) == adFldIsNullable);
208 }
209 return sal_Int32(false);
210}
211
212
213sal_Bool SAL_CALL OResultSetMetaData::isSearchable( sal_Int32 /*column*/ )
214{
215 return true;
216}
217
218
219sal_Bool SAL_CALL OResultSetMetaData::isReadOnly( sal_Int32 column )
220{
221 WpADOField aField = ADOS::getField(m_pRecordSet,column);
222 if(aField.IsValid())
223 {
224 // return (aField.GetStatus() & adFieldReadOnly) == adFieldReadOnly;
225 }
226 return false;
227}
228
229
231{
232 WpADOField aField = ADOS::getField(m_pRecordSet,column);
233 if(aField.IsValid())
234 {
235 return (aField.GetAttributes() & adFldUpdatable) == adFldUpdatable;
236 }
237 return false;
238;
239}
240
241sal_Bool SAL_CALL OResultSetMetaData::isWritable( sal_Int32 column )
242{
243 return isDefinitelyWritable(column);
244}
245
246
247/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static sal_Int32 MapADOType2Jdbc(DataTypeEnum eType)
Definition: adoimp.cxx:78
static WpADOField getField(ADORecordset *_pRecordSet, sal_Int32 _nColumnIndex)
Definition: adoimp.cxx:309
virtual sal_Bool SAL_CALL isSearchable(sal_Int32 column) override
virtual sal_Int32 SAL_CALL getPrecision(sal_Int32 column) override
virtual OUString SAL_CALL getSchemaName(sal_Int32 column) override
virtual sal_Bool SAL_CALL isCaseSensitive(sal_Int32 column) override
virtual sal_Bool SAL_CALL isCurrency(sal_Int32 column) override
virtual sal_Int32 SAL_CALL getColumnType(sal_Int32 column) override
virtual OUString SAL_CALL getColumnTypeName(sal_Int32 column) override
virtual sal_Bool SAL_CALL isReadOnly(sal_Int32 column) override
virtual OUString SAL_CALL getColumnLabel(sal_Int32 column) override
virtual sal_Bool SAL_CALL isWritable(sal_Int32 column) override
virtual sal_Bool SAL_CALL isAutoIncrement(sal_Int32 column) override
virtual OUString SAL_CALL getCatalogName(sal_Int32 column) override
virtual sal_Int32 SAL_CALL isNullable(sal_Int32 column) override
virtual OUString SAL_CALL getColumnServiceName(sal_Int32 column) override
virtual sal_Bool SAL_CALL isSigned(sal_Int32 column) override
virtual OUString SAL_CALL getTableName(sal_Int32 column) override
virtual sal_Int32 SAL_CALL getColumnCount() override
virtual OUString SAL_CALL getColumnName(sal_Int32 column) override
virtual sal_Int32 SAL_CALL getScale(sal_Int32 column) override
virtual sal_Int32 SAL_CALL getColumnDisplaySize(sal_Int32 column) override
virtual sal_Bool SAL_CALL isDefinitelyWritable(sal_Int32 column) override
static OLEVariant getValue(const WpADOProperties &_rProps, const OLEVariant &_aPosition)
getValue returns a specific property value
Definition: Awrapado.cxx:2003
DataTypeEnum GetADOType() const
Definition: Awrapado.cxx:478
WpADOProperties get_Properties()
Definition: Awrapado.cxx:430
OUString GetName() const
Definition: Awrapado.cxx:470
sal_Int32 GetActualSize() const
Definition: Awrapado.cxx:438
sal_Int32 GetPrecision() const
Definition: Awrapado.cxx:507
sal_Int32 GetNumericScale() const
Definition: Awrapado.cxx:515
sal_Int32 GetAttributes() const
Definition: Awrapado.cxx:446
float u
DocumentType eType
static ColumnProperty ** pFields
unsigned char sal_Bool