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
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>
29
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;
36
OResultSetMetaData(ADORecordset * _pRecordSet)37 OResultSetMetaData::OResultSetMetaData( ADORecordset* _pRecordSet)
38 : m_pRecordSet(_pRecordSet),
39 m_nColCount(-1)
40 {
41 if ( m_pRecordSet )
42 m_pRecordSet->AddRef();
43 }
44
~OResultSetMetaData()45 OResultSetMetaData::~OResultSetMetaData()
46 {
47 if ( m_pRecordSet )
48 m_pRecordSet->Release();
49 }
50
getColumnDisplaySize(sal_Int32 column)51 sal_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
getColumnType(sal_Int32 column)60 sal_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
getColumnCount()67 sal_Int32 SAL_CALL OResultSetMetaData::getColumnCount( )
68 {
69 if(m_nColCount != -1 )
70 return m_nColCount;
71
72 if ( !m_pRecordSet )
73 return 0;
74
75 ADOFields* pFields = nullptr;
76 m_pRecordSet->get_Fields(&pFields);
77 WpOLEAppendCollection<ADOFields, ADOField, WpADOField> aFields(pFields);
78 m_nColCount = aFields.GetItemCount();
79 return m_nColCount;
80 }
81
82
isCaseSensitive(sal_Int32 column)83 sal_Bool SAL_CALL OResultSetMetaData::isCaseSensitive( sal_Int32 column )
84 {
85 bool bRet = false;
86 WpADOField aField = ADOS::getField(m_pRecordSet,column);
87 if ( aField.IsValid() )
88 {
89 WpADOProperties aProps( aField.get_Properties() );
90 if ( aProps.IsValid() )
91 bRet = OTools::getValue(aProps, std::u16string_view(u"ISCASESENSITIVE")).getBool();
92 }
93 return bRet;
94 }
95
96
getSchemaName(sal_Int32)97 OUString SAL_CALL OResultSetMetaData::getSchemaName( sal_Int32 /*column*/ )
98 {
99 return OUString();
100 }
101
102
getColumnName(sal_Int32 column)103 OUString SAL_CALL OResultSetMetaData::getColumnName( sal_Int32 column )
104 {
105 WpADOField aField = ADOS::getField(m_pRecordSet,column);
106 if(aField.IsValid())
107 return aField.GetName();
108
109 return OUString();
110 }
111
getTableName(sal_Int32 column)112 OUString SAL_CALL OResultSetMetaData::getTableName( sal_Int32 column )
113 {
114 OUString sTableName;
115
116 WpADOField aField = ADOS::getField(m_pRecordSet,column);
117 if ( aField.IsValid() )
118 {
119 WpADOProperties aProps( aField.get_Properties() );
120 if ( aProps.IsValid() )
121 sTableName
122 = OTools::getValue(aProps, std::u16string_view(u"BASETABLENAME")).getString();
123 }
124 return sTableName;
125 }
126
getCatalogName(sal_Int32)127 OUString SAL_CALL OResultSetMetaData::getCatalogName( sal_Int32 /*column*/ )
128 {
129 return OUString();
130 }
131
getColumnTypeName(sal_Int32)132 OUString SAL_CALL OResultSetMetaData::getColumnTypeName( sal_Int32 /*column*/ )
133 {
134 return OUString();
135 }
136
getColumnLabel(sal_Int32 column)137 OUString SAL_CALL OResultSetMetaData::getColumnLabel( sal_Int32 column )
138 {
139 return getColumnName(column);
140 }
141
getColumnServiceName(sal_Int32)142 OUString SAL_CALL OResultSetMetaData::getColumnServiceName( sal_Int32 /*column*/ )
143 {
144 return OUString();
145 }
146
147
isCurrency(sal_Int32 column)148 sal_Bool SAL_CALL OResultSetMetaData::isCurrency( sal_Int32 column )
149 {
150 WpADOField aField = ADOS::getField(m_pRecordSet,column);
151 if(aField.IsValid())
152 {
153 return ((aField.GetAttributes() & adFldFixed) == adFldFixed) && (aField.GetADOType() == adCurrency);
154 }
155 return false;
156 }
157
158
isAutoIncrement(sal_Int32 column)159 sal_Bool SAL_CALL OResultSetMetaData::isAutoIncrement( sal_Int32 column )
160 {
161 bool bRet = false;
162 WpADOField aField = ADOS::getField(m_pRecordSet,column);
163 if ( aField.IsValid() )
164 {
165 WpADOProperties aProps( aField.get_Properties() );
166 if ( aProps.IsValid() )
167 {
168 bRet = OTools::getValue(aProps, std::u16string_view(u"ISAUTOINCREMENT")).getBool();
169 }
170 }
171 return bRet;
172 }
173
174
isSigned(sal_Int32 column)175 sal_Bool SAL_CALL OResultSetMetaData::isSigned( sal_Int32 column )
176 {
177 WpADOField aField = ADOS::getField(m_pRecordSet,column);
178 if(aField.IsValid())
179 {
180 DataTypeEnum eType = aField.GetADOType();
181 return !(eType == adUnsignedBigInt || eType == adUnsignedInt || eType == adUnsignedSmallInt || eType == adUnsignedTinyInt);
182 }
183 return false;
184 }
185
getPrecision(sal_Int32 column)186 sal_Int32 SAL_CALL OResultSetMetaData::getPrecision( sal_Int32 column )
187 {
188 WpADOField aField = ADOS::getField(m_pRecordSet,column);
189 if(aField.IsValid())
190 return aField.GetPrecision();
191 return 0;
192 }
193
getScale(sal_Int32 column)194 sal_Int32 SAL_CALL OResultSetMetaData::getScale( sal_Int32 column )
195 {
196 WpADOField aField = ADOS::getField(m_pRecordSet,column);
197 if(aField.IsValid())
198 return aField.GetNumericScale();
199 return 0;
200 }
201
202
isNullable(sal_Int32 column)203 sal_Int32 SAL_CALL OResultSetMetaData::isNullable( sal_Int32 column )
204 {
205 WpADOField aField = ADOS::getField(m_pRecordSet,column);
206 if(aField.IsValid())
207 {
208 return sal_Int32((aField.GetAttributes() & adFldIsNullable) == adFldIsNullable);
209 }
210 return sal_Int32(false);
211 }
212
213
isSearchable(sal_Int32)214 sal_Bool SAL_CALL OResultSetMetaData::isSearchable( sal_Int32 /*column*/ )
215 {
216 return true;
217 }
218
219
isReadOnly(sal_Int32 column)220 sal_Bool SAL_CALL OResultSetMetaData::isReadOnly( sal_Int32 column )
221 {
222 WpADOField aField = ADOS::getField(m_pRecordSet,column);
223 if(aField.IsValid())
224 {
225 // return (aField.GetStatus() & adFieldReadOnly) == adFieldReadOnly;
226 }
227 return false;
228 }
229
230
isDefinitelyWritable(sal_Int32 column)231 sal_Bool SAL_CALL OResultSetMetaData::isDefinitelyWritable( sal_Int32 column )
232 {
233 WpADOField aField = ADOS::getField(m_pRecordSet,column);
234 if(aField.IsValid())
235 {
236 return (aField.GetAttributes() & adFldUpdatable) == adFldUpdatable;
237 }
238 return false;
239 ;
240 }
241
isWritable(sal_Int32 column)242 sal_Bool SAL_CALL OResultSetMetaData::isWritable( sal_Int32 column )
243 {
244 return isDefinitelyWritable(column);
245 }
246
247
248 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
249