LibreOffice Module connectivity (master) 1
ADatabaseMetaDataImpl.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
26#include <ado/Awrapado.hxx>
27#include <ado/AGroup.hxx>
28#include <ado/adoimp.hxx>
29#include <ado/AIndex.hxx>
30#include <ado/AKey.hxx>
31#include <ado/ATable.hxx>
32
33#include <systools/win32/oleauto.hxx>
34
35#include <com/sun/star/sdbc/DataType.hpp>
36#include <com/sun/star/sdbc/ProcedureResult.hpp>
37#include <com/sun/star/sdbc/ColumnValue.hpp>
38#ifdef DELETE
39#undef DELETE
40#endif
41#include <com/sun/star/sdbcx/Privilege.hpp>
42#include <com/sun/star/sdbcx/PrivilegeObject.hpp>
43#include <com/sun/star/sdbc/KeyRule.hpp>
44#include <com/sun/star/sdbcx/KeyType.hpp>
45
46using namespace connectivity::ado;
47using namespace ::com::sun::star::sdbc;
48using namespace ::com::sun::star::sdbcx;
49using namespace ::com::sun::star::uno;
50
51
52void ODatabaseMetaData::fillLiterals()
53{
54 WpADORecordset aRecordset;
55 OLEVariant vtEmpty;
56 vtEmpty.setNoArg();
57 m_rADOConnection.OpenSchema(adSchemaDBInfoLiterals,vtEmpty,vtEmpty,&aRecordset);
58
60
61 OSL_ENSURE(aRecordset,"fillLiterals: no resultset!");
62 if ( aRecordset )
63 {
64 aRecordset.MoveFirst();
65 OLEVariant aValue;
66 LiteralInfo aInfo;
67 while(!aRecordset.IsAtEOF())
68 {
70 WpADOField aField(aFields.GetItem(1));
71 aInfo.pwszLiteralValue = aField.get_Value().getString();
72 aField = aFields.GetItem(5);
73 aInfo.fSupported = aField.get_Value().getBool();
74 aField = aFields.GetItem(6);
75 aInfo.cchMaxLen = aField.get_Value().getUInt32();
76
77 aField = aFields.GetItem(4);
78 sal_uInt32 nId = aField.get_Value().getUInt32();
79 m_aLiteralInfo[nId] = aInfo;
80
81 aRecordset.MoveNext();
82 }
83 aRecordset.Close();
84 }
85}
86
87sal_Int32 ODatabaseMetaData::getMaxSize(sal_uInt32 _nId)
88{
89 if(m_aLiteralInfo.empty())
91
92 sal_Int32 nSize = 0;
93 std::map<sal_uInt32,LiteralInfo>::const_iterator aIter = m_aLiteralInfo.find(_nId);
94 if(aIter != m_aLiteralInfo.end() && (*aIter).second.fSupported)
95 nSize = (static_cast<sal_Int32>((*aIter).second.cchMaxLen) == -1) ? 0 : (*aIter).second.cchMaxLen;
96 return nSize;
97}
98
99bool ODatabaseMetaData::isCapable(sal_uInt32 _nId)
100{
101 if(m_aLiteralInfo.empty())
102 fillLiterals();
103 bool bSupported = false;
104 std::map<sal_uInt32,LiteralInfo>::const_iterator aIter = m_aLiteralInfo.find(_nId);
105 if(aIter != m_aLiteralInfo.end())
106 bSupported = (*aIter).second.fSupported;
107 return bSupported;
108}
109
110
111OUString ODatabaseMetaData::getLiteral(sal_uInt32 _nId)
112{
113 if(m_aLiteralInfo.empty())
114 fillLiterals();
115 OUString sStr;
116 std::map<sal_uInt32,LiteralInfo>::const_iterator aIter = m_aLiteralInfo.find(_nId);
117 if(aIter != m_aLiteralInfo.end() && (*aIter).second.fSupported)
118 sStr = (*aIter).second.pwszLiteralValue;
119 return sStr;
120}
121
122
124{
125 m_mColumns[8] = OColumn(OUString(),"IS_GRANTABLE",
126 ColumnValue::NULLABLE,
127 3,3,0,
128 DataType::VARCHAR);
129}
130
132{
133 m_mColumns[6] = OColumn(OUString(),"TYPE_NAME",
134 ColumnValue::NO_NULLS,
135 0,0,0,
136 DataType::VARCHAR);
137 m_mColumns[11] = OColumn(OUString(),"NULLABLE",
138 ColumnValue::NO_NULLS,
139 1,1,0,
140 DataType::INTEGER);
141 m_mColumns[12] = OColumn(OUString(),"REMARKS",
142 ColumnValue::NULLABLE,
143 0,0,0,
144 DataType::VARCHAR);
145 m_mColumns[13] = OColumn(OUString(),"COLUMN_DEF",
146 ColumnValue::NULLABLE,
147 0,0,0,
148 DataType::VARCHAR);
149 m_mColumns[14] = OColumn(OUString(),"SQL_DATA_TYPE",
150 ColumnValue::NO_NULLS,
151 1,1,0,
152 DataType::INTEGER);
153 m_mColumns[15] = OColumn(OUString(),"SQL_DATETIME_SUB",
154 ColumnValue::NO_NULLS,
155 1,1,0,
156 DataType::INTEGER);
157 m_mColumns[16] = OColumn(OUString(),"CHAR_OCTET_LENGTH",
158 ColumnValue::NO_NULLS,
159 1,1,0,
160 DataType::INTEGER);
161}
162
164{
165 m_mColumns[5] = OColumn(OUString(),"REMARKS",
166 ColumnValue::NULLABLE,
167 0,0,0,
168 DataType::VARCHAR);
169}
170
172{
173 m_mColumns[12] = OColumn(OUString(),"NULLABLE",
174 ColumnValue::NO_NULLS,
175 1,1,0,
176 DataType::INTEGER);
177}
178
180{
181 m_mColumns[5] = OColumn(OUString(),"KEY_SEQ",
182 ColumnValue::NO_NULLS,
183 1,1,0,
184 DataType::INTEGER);
185 m_mColumns[6] = OColumn(OUString(),"PK_NAME",
186 ColumnValue::NULLABLE,
187 0,0,0,
188 DataType::VARCHAR);
189}
190
192{
193 m_mColumns[4] = OColumn(OUString(),"NON_UNIQUE",
194 ColumnValue::NO_NULLS,
195 1,1,0,
196 DataType::BIT);
197 m_mColumns[5] = OColumn(OUString(),"INDEX_QUALIFIER",
198 ColumnValue::NULLABLE,
199 0,0,0,
200 DataType::VARCHAR);
201 m_mColumns[10] = OColumn(OUString(),"ASC_OR_DESC",
202 ColumnValue::NULLABLE,
203 0,0,0,
204 DataType::VARCHAR);
205}
206
208{
209 m_mColumns[6] = OColumn(OUString(),"PRIVILEGE",
210 ColumnValue::NULLABLE,
211 0,0,0,
212 DataType::VARCHAR);
213 m_mColumns[7] = OColumn(OUString(),"IS_GRANTABLE",
214 ColumnValue::NULLABLE,
215 0,0,0,
216 DataType::VARCHAR);
217}
218
220{
221 m_mColumns[9] = OColumn(OUString(),"KEY_SEQ",
222 ColumnValue::NO_NULLS,
223 1,1,0,
224 DataType::INTEGER);
225}
226
228{
229 m_mColumns[3] = OColumn(OUString(),"PRECISION",
230 ColumnValue::NO_NULLS,
231 1,1,0,
232 DataType::INTEGER);
233 m_mColumns[7] = OColumn(OUString(),"NULLABLE",
234 ColumnValue::NO_NULLS,
235 1,1,0,
236 DataType::INTEGER);
237 m_mColumns[12] = OColumn(OUString(),"AUTO_INCREMENT",
238 ColumnValue::NO_NULLS,
239 1,1,0,
240 DataType::BIT);
241 m_mColumns[16] = OColumn(OUString(),"SQL_DATA_TYPE",
242 ColumnValue::NO_NULLS,
243 1,1,0,
244 DataType::INTEGER);
245 m_mColumns[17] = OColumn(OUString(),"SQL_DATETIME_SUB",
246 ColumnValue::NO_NULLS,
247 1,1,0,
248 DataType::INTEGER);
249 m_mColumns[18] = OColumn(OUString(),"NUM_PREC_RADIX",
250 ColumnValue::NO_NULLS,
251 1,1,0,
252 DataType::INTEGER);
253}
254
256{
257 m_mColumns[7] = OColumn(OUString(),"REMARKS",
258 ColumnValue::NULLABLE,
259 0,0,0,
260 DataType::VARCHAR);
261}
262
264{
265 if(!m_mColumns.empty() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end())
266 return (*m_mColumnsIter).second.isSearchable();
267 return true;
268}
269
271{
272 if(!m_mColumns.empty() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end())
273 return (*m_mColumnsIter).second.isAutoIncrement();
274 return false;
275}
276
277OUString SAL_CALL ODatabaseMetaDataResultSetMetaData::getColumnServiceName( sal_Int32 /*column*/ )
278{
279 return OUString();
280}
281
282OUString SAL_CALL ODatabaseMetaDataResultSetMetaData::getTableName( sal_Int32 column )
283{
284 if(!m_mColumns.empty() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end())
285 return (*m_mColumnsIter).second.getTableName();
286 return OUString();
287}
288
289OUString SAL_CALL ODatabaseMetaDataResultSetMetaData::getCatalogName( sal_Int32 /*column*/ )
290{
291 return OUString();
292}
293
294OUString SAL_CALL ODatabaseMetaDataResultSetMetaData::getColumnTypeName( sal_Int32 /*column*/ )
295{
296 return OUString();
297}
298
299
301{
302 if(!m_mColumns.empty() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end())
303 return (*m_mColumnsIter).second.isCaseSensitive();
304 return true;
305}
306
307
308OUString SAL_CALL ODatabaseMetaDataResultSetMetaData::getSchemaName( sal_Int32 /*column*/ )
309{
310 return OUString();
311}
312
313
314ObjectTypeEnum OAdoGroup::MapObjectType(sal_Int32 ObjType)
315{
316 ObjectTypeEnum eNumType= adPermObjTable;
317 switch(ObjType)
318 {
319 case PrivilegeObject::TABLE:
320 break;
321 case PrivilegeObject::VIEW:
322 eNumType = adPermObjView;
323 break;
324 case PrivilegeObject::COLUMN:
325 eNumType = adPermObjColumn;
326 break;
327 }
328 return eNumType;
329}
330
331sal_Int32 OAdoGroup::MapRight(RightsEnum _eNum)
332{
333 sal_Int32 nRight = 0;
334 if(_eNum & adRightRead)
335 nRight |= Privilege::SELECT;
336 if(_eNum & adRightInsert)
337 nRight |= Privilege::INSERT;
338 if(_eNum & adRightUpdate)
339 nRight |= Privilege::UPDATE;
340 if(_eNum & adRightDelete)
341 nRight |= Privilege::DELETE;
342 if(_eNum & adRightReadDesign)
343 nRight |= Privilege::READ;
344 if(_eNum & adRightCreate)
345 nRight |= Privilege::CREATE;
346 if(_eNum & adRightWriteDesign)
347 nRight |= Privilege::ALTER;
348 if(_eNum & adRightReference)
349 nRight |= Privilege::REFERENCE;
350 if(_eNum & adRightDrop)
351 nRight |= Privilege::DROP;
352
353 return nRight;
354}
355
356RightsEnum OAdoGroup::Map2Right(sal_Int32 _eNum)
357{
358 sal_Int32 nRight = adRightNone;
359 if(_eNum & Privilege::SELECT)
360 nRight |= adRightRead;
361
362 if(_eNum & Privilege::INSERT)
363 nRight |= adRightInsert;
364
365 if(_eNum & Privilege::UPDATE)
366 nRight |= adRightUpdate;
367
368 if(_eNum & Privilege::DELETE)
369 nRight |= adRightDelete;
370
371 if(_eNum & Privilege::READ)
372 nRight |= adRightReadDesign;
373
374 if(_eNum & Privilege::CREATE)
375 nRight |= adRightCreate;
376
377 if(_eNum & Privilege::ALTER)
378 nRight |= adRightWriteDesign;
379
380 if(_eNum & Privilege::REFERENCE)
381 nRight |= adRightReference;
382
383 if(_eNum & Privilege::DROP)
384 nRight |= adRightDrop;
385
386 return static_cast<RightsEnum>(nRight);
387}
388
390{
391 pInterface.CoCreateInstance(ADOS::CLSID_ADOINDEX_25, nullptr, CLSCTX_INPROC_SERVER);
392}
393
395{
396 if(m_aIndex.IsValid())
397 {
402 }
403}
404
406{
407 pInterface.CoCreateInstance(ADOS::CLSID_ADOKEY_25, nullptr, CLSCTX_INPROC_SERVER);
408}
409
411{
412 if(m_aKey.IsValid())
413 {
414 m_aProps->m_Type = MapKeyRule(m_aKey.get_Type());
416 m_aProps->m_ReferencedTable = m_aKey.get_RelatedTable();
417 m_aProps->m_UpdateRule = MapRule(m_aKey.get_UpdateRule());
418 m_aProps->m_DeleteRule = MapRule(m_aKey.get_DeleteRule());
419 }
420}
421
422sal_Int32 OAdoKey::MapRule(const RuleEnum& _eNum)
423{
424 sal_Int32 eNum = KeyRule::NO_ACTION;
425 switch(_eNum)
426 {
427 case adRICascade:
428 eNum = KeyRule::CASCADE;
429 break;
430 case adRISetNull:
431 eNum = KeyRule::SET_NULL;
432 break;
433 case adRINone:
434 eNum = KeyRule::NO_ACTION;
435 break;
436 case adRISetDefault:
437 eNum = KeyRule::SET_DEFAULT;
438 break;
439 }
440 return eNum;
441}
442
443RuleEnum OAdoKey::Map2Rule(sal_Int32 _eNum)
444{
445 RuleEnum eNum = adRINone;
446 switch(_eNum)
447 {
448 case KeyRule::CASCADE:
449 eNum = adRICascade;
450 break;
451 case KeyRule::SET_NULL:
452 eNum = adRISetNull;
453 break;
454 case KeyRule::NO_ACTION:
455 eNum = adRINone;
456 break;
457 case KeyRule::SET_DEFAULT:
458 eNum = adRISetDefault;
459 break;
460 }
461 return eNum;
462}
463
464sal_Int32 OAdoKey::MapKeyRule(const KeyTypeEnum& _eNum)
465{
466 sal_Int32 nKeyType = KeyType::PRIMARY;
467 switch(_eNum)
468 {
469 case adKeyPrimary:
470 nKeyType = KeyType::PRIMARY;
471 break;
472 case adKeyForeign:
473 nKeyType = KeyType::FOREIGN;
474 break;
475 case adKeyUnique:
476 nKeyType = KeyType::UNIQUE;
477 break;
478 }
479 return nKeyType;
480}
481
482KeyTypeEnum OAdoKey::Map2KeyRule(sal_Int32 _eNum)
483{
484 KeyTypeEnum eNum( adKeyPrimary );
485 switch(_eNum)
486 {
487 case KeyType::PRIMARY:
488 eNum = adKeyPrimary;
489 break;
490 case KeyType::FOREIGN:
491 eNum = adKeyForeign;
492 break;
493 case KeyType::UNIQUE:
494 eNum = adKeyUnique;
495 break;
496 default:
497 OSL_FAIL( "OAdoKey::Map2KeyRule: invalid key type!" );
498 }
499 return eNum;
500}
501
503{
504 pInterface.CoCreateInstance(ADOS::CLSID_ADOTABLE_25, nullptr, CLSCTX_INPROC_SERVER);
505}
506
507OUString WpADOCatalog::GetObjectOwner(std::u16string_view _rName, ObjectTypeEnum _eNum)
508{
509 OLEVariant _rVar;
510 _rVar.setNoArg();
511 sal::systools::BStr aBSTR;
512 sal::systools::BStr sStr1(_rName);
513 pInterface->GetObjectOwner(sStr1, _eNum, _rVar, &aBSTR);
514 return OUString(aBSTR);
515}
516
518{
519 if(m_aTable.IsValid())
520 {
523 {
525 if(aCat.IsValid())
526 m_CatalogName = aCat.GetObjectOwner(m_aTable.get_Name(),adPermObjTable);
527 }
528 {
530 if(aProps.IsValid())
532 = OTools::getValue(aProps, std::u16string_view(u"Description")).getString();
533 }
534 }
535}
536
538{
539 pInterface.CoCreateInstance(ADOS::CLSID_ADOUSER_25, nullptr, CLSCTX_INPROC_SERVER);
540}
541
542
543/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static const CLSID CLSID_ADOTABLE_25
Definition: adoimp.hxx:60
static void ThrowException(ADOConnection *_pAdoCon, const css::uno::Reference< css::uno::XInterface > &_xInterface)
Definition: ADriver.cxx:207
static const CLSID CLSID_ADOKEY_25
Definition: adoimp.hxx:57
static const CLSID CLSID_ADOUSER_25
Definition: adoimp.hxx:66
static const CLSID CLSID_ADOINDEX_25
Definition: adoimp.hxx:51
static RightsEnum Map2Right(sal_Int32 _eNum)
static sal_Int32 MapRight(RightsEnum _eNum)
static ObjectTypeEnum MapObjectType(sal_Int32 ObjType)
static RuleEnum Map2Rule(sal_Int32 _eNum)
static KeyTypeEnum Map2KeyRule(sal_Int32 _eNum)
static sal_Int32 MapRule(const RuleEnum &_eNum)
static sal_Int32 MapKeyRule(const KeyTypeEnum &_eNum)
virtual OUString SAL_CALL getColumnServiceName(sal_Int32 column) override
std::map< sal_Int32, connectivity::OColumn >::const_iterator m_mColumnsIter
virtual OUString SAL_CALL getColumnTypeName(sal_Int32 column) override
virtual OUString SAL_CALL getSchemaName(sal_Int32 column) override
virtual sal_Bool SAL_CALL isCaseSensitive(sal_Int32 column) override
virtual OUString SAL_CALL getCatalogName(sal_Int32 column) override
virtual OUString SAL_CALL getTableName(sal_Int32 column) override
virtual sal_Bool SAL_CALL isAutoIncrement(sal_Int32 column) override
virtual sal_Bool SAL_CALL isSearchable(sal_Int32 column) override
OUString getLiteral(sal_uInt32 _nProperty)
std::map< sal_uInt32, LiteralInfo > m_aLiteralInfo
static OLEVariant getValue(const WpADOProperties &_rProps, const OLEVariant &_aPosition)
getValue returns a specific property value
Definition: Awrapado.cxx:2003
OUString GetObjectOwner(std::u16string_view _rName, ObjectTypeEnum _eNum)
bool OpenSchema(SchemaEnum eNum, OLEVariant const &Restrictions, OLEVariant const &SchemaID, ADORecordset **pprset)
Definition: Awrapado.cxx:232
void get_Value(OLEVariant &aValVar) const
Definition: Awrapado.cxx:486
RuleEnum get_DeleteRule() const
Definition: Awrapado.cxx:1136
KeyTypeEnum get_Type() const
Definition: Awrapado.cxx:1107
OUString get_RelatedTable() const
Definition: Awrapado.cxx:1121
RuleEnum get_UpdateRule() const
Definition: Awrapado.cxx:1150
OUString get_Name() const
Definition: Awrapado.cxx:1092
WpADOFields GetFields() const
Definition: Awrapado.cxx:765
WpADOProperties get_Properties() const
Definition: Awrapado.cxx:1338
WpADOCatalog get_ParentCatalog() const
Definition: Awrapado.cxx:1330
sal::systools::COMReference< _ADOIndex > pInterface
Definition: Aolewrap.hxx:44
WrapT GetItem(sal_Int32 index) const
Definition: Aolewrap.hxx:102
std::shared_ptr< KeyProperties > m_aProps
Definition: VKey.hxx:68
float u
sal_Int16 nId
unsigned char sal_Bool