LibreOffice Module connectivity (master) 1
TDatabaseMetaDataBase.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 <cstddef>
23
25#include <RowFunctionParser.hxx>
26
29#include <comphelper/types.hxx>
30#include <com/sun/star/lang/XComponent.hpp>
32#include <strings.hrc>
34#include <sal/macros.h>
35
36using namespace com::sun::star::uno;
37using namespace com::sun::star::lang;
38using namespace com::sun::star::sdbc;
39using namespace com::sun::star::beans;
40using namespace comphelper;
41using namespace connectivity;
42
43
44ODatabaseMetaDataBase::ODatabaseMetaDataBase(const Reference< XConnection >& _rxConnection,const Sequence< PropertyValue >& _rInfo)
45 : m_aConnectionInfo(_rInfo)
46 ,m_isCatalogAtStart(false,false)
47 ,m_sCatalogSeparator(false,OUString())
48 ,m_sIdentifierQuoteString(false,OUString())
49 ,m_supportsCatalogsInTableDefinitions(false,false)
50 ,m_supportsSchemasInTableDefinitions(false,false)
51 ,m_supportsCatalogsInDataManipulation(false,false)
52 ,m_supportsSchemasInDataManipulation(false,false)
53 ,m_supportsMixedCaseQuotedIdentifiers(false,false)
54 ,m_supportsAlterTableWithAddColumn(false,false)
55 ,m_supportsAlterTableWithDropColumn(false,false)
56 ,m_MaxStatements(false,0)
57 ,m_MaxTablesInSelect(false,0)
58 ,m_storesMixedCaseQuotedIdentifiers(false,false)
59 , m_xConnection(_rxConnection)
60{
61 osl_atomic_increment( &m_refCount );
62 {
63 m_xListenerHelper = new OEventListenerHelper(this);
65 if(xCom.is())
66 xCom->addEventListener(m_xListenerHelper);
67 }
68 osl_atomic_decrement( &m_refCount );
69}
70
72{
73}
74
75
77{
78 return m_aConnectionInfo;
79}
80
81
82void SAL_CALL ODatabaseMetaDataBase::disposing( const EventObject& /*Source*/ )
83{
84 // cut off all references to the connection
85m_xConnection.clear();
86m_xListenerHelper.clear();
87}
88
90{
91 ::osl::MutexGuard aGuard( m_aMutex );
92 if ( m_aTypeInfoRows.empty() )
93 {
95 Reference< XRow > xRow(xRet,UNO_QUERY);
97 Sequence< Any > aTypeInfoSettings;
98 aTypeInfoSettings = aMap.getUnpackedValueOrDefault("TypeInfoSettings",aTypeInfoSettings);
99
100 if ( xRow.is() )
101 {
102 static const sal_Int32 pTypes[] = {
103 DataType::VARCHAR
104 ,DataType::INTEGER
105 ,DataType::INTEGER
106 ,DataType::VARCHAR
107 ,DataType::VARCHAR
108 ,DataType::VARCHAR
109 ,DataType::INTEGER
110 ,DataType::BOOLEAN
111 ,DataType::INTEGER
112 ,DataType::BOOLEAN
113 ,DataType::BOOLEAN
114 ,DataType::BOOLEAN
115 ,DataType::VARCHAR
116 ,DataType::INTEGER
117 ,DataType::INTEGER
118 ,DataType::INTEGER
119 ,DataType::INTEGER
120 ,DataType::INTEGER
121 };
122 std::vector<std::shared_ptr<ExpressionNode>> aConditions;
123 if ( aTypeInfoSettings.getLength() > 1 && ((aTypeInfoSettings.getLength() % 2) == 0) )
124 {
125 const Any* pIter = aTypeInfoSettings.getConstArray();
126 const Any* pEnd = pIter + aTypeInfoSettings.getLength();
127 try
128 {
129 for(;pIter != pEnd;++pIter)
130 aConditions.push_back(FunctionParser::parseFunction(::comphelper::getString(*pIter)));
131 }
132 catch(ParseError&)
133 {
135 const OUString sError( aResources.getResourceString(STR_FORMULA_WRONG));
137 }
138 }
139
141 while( xRet->next() )
142 {
145 const sal_Int32* pType = pTypes;
146 for (std::size_t i = 1; i <= std::size(pTypes); ++i,++pType)
147 {
148 ORowSetValue aValue;
149 aValue.fill(i,*pType,xRow);
150 aRow.push_back(new ORowSetValueDecorator(std::move(aValue)));
151 }
152
153 std::vector<std::shared_ptr<ExpressionNode>>::iterator aIter = aConditions.begin();
154 std::vector<std::shared_ptr<ExpressionNode>>::const_iterator aEnd = aConditions.end();
155 for (; aIter != aEnd; ++aIter)
156 {
157 if ( (*aIter)->evaluate(aRow)->getValue().getBool() )
158 {
159 ++aIter;
160 (*aIter)->fill(aRow);
161 }
162 else
163 ++aIter;
164 }
165 aTypeInfoRows.push_back(aRow);
166 }
167 m_aTypeInfoRows = aTypeInfoRows;
168 }
169 }
171 pResult->setRows(std::vector(m_aTypeInfoRows));
172 return pResult;
173}
174
176 const Any& /*catalog*/, const OUString& /*schema*/, const OUString& /*table*/ )
177{
179}
180
182 const Any& /*catalog*/, const OUString& /*schema*/, const OUString& /*table*/ )
183{
185}
186
188 const Any& /*catalog*/, const OUString& /*schema*/, const OUString& /*table*/ )
189{
191}
192
194 const Any& /*catalog*/, const OUString& /*schema*/, const OUString& /*table*/,
195 sal_Bool /*unique*/, sal_Bool /*approximate*/ )
196{
198}
199
201 const Any& /*catalog*/, const OUString& /*schema*/, const OUString& /*table*/, sal_Int32 /*scope*/,
202 sal_Bool /*nullable*/ )
203{
205}
206
208 const Any& /*primaryCatalog*/, const OUString& /*primarySchema*/,
209 const OUString& /*primaryTable*/, const Any& /*foreignCatalog*/,
210 const OUString& /*foreignSchema*/, const OUString& /*foreignTable*/ )
211{
213}
214
216{
217 return m_xConnection;
218}
219
221 const Any& /*catalog*/, const OUString& /*schemaPattern*/,
222 const OUString& /*procedureNamePattern*/, const OUString& /*columnNamePattern*/ )
223{
225}
226
228 const Any& /*catalog*/, const OUString& /*schemaPattern*/,
229 const OUString& /*procedureNamePattern*/ )
230{
232}
233
235 const Any& /*catalog*/, const OUString& /*schema*/, const OUString& /*table*/ )
236{
238}
239
241{
243}
244
246 const Any& /*catalog*/, const OUString& /*schema*/, const OUString& /*table*/,
247 const OUString& /*columnNamePattern*/ )
248{
250}
251
253 const Any& /*catalog*/, const OUString& /*schema*/, const OUString& /*table*/)
254{
256}
257
259{
261}
262
264{
266}
267
269{
271}
272
274{
276}
277
279{
281}
282
284{
286}
287
289{
291}
292
294{
296}
297
299{
301}
302
304{
306}
307
309{
311}
312
314{
316}
317
319{
321}
322
324{
326}
327
328
329/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static std::shared_ptr< ExpressionNode > const & parseFunction(const OUString &_sFunction)
Parse a string.
virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getProcedureColumns(const css::uno::Any &catalog, const OUString &schemaPattern, const OUString &procedureNamePattern, const OUString &columnNamePattern) override
css::uno::Sequence< css::beans::PropertyValue > m_aConnectionInfo
virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getCrossReference(const css::uno::Any &primaryCatalog, const OUString &primarySchema, const OUString &primaryTable, const css::uno::Any &foreignCatalog, const OUString &foreignSchema, const OUString &foreignTable) override
virtual css::uno::Sequence< css::beans::PropertyValue > SAL_CALL getConnectionInfo() override
std::pair< bool, sal_Int32 > m_MaxTablesInSelect
virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getPrimaryKeys(const css::uno::Any &catalog, const OUString &schema, const OUString &table) override
virtual sal_Bool SAL_CALL supportsAlterTableWithAddColumn() override
virtual void SAL_CALL disposing(const css::lang::EventObject &Source) override
std::pair< bool, sal_Int32 > m_MaxStatements
virtual bool impl_supportsSchemasInTableDefinitions_throw()=0
css::uno::Reference< css::lang::XEventListener > m_xListenerHelper
std::pair< bool, OUString > m_sIdentifierQuoteString
std::pair< bool, bool > m_supportsCatalogsInTableDefinitions
virtual sal_Int32 impl_getMaxStatements_throw()=0
virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getVersionColumns(const css::uno::Any &catalog, const OUString &schema, const OUString &table) override
virtual sal_Bool SAL_CALL isCatalogAtStart() override
virtual sal_Bool SAL_CALL supportsSchemasInTableDefinitions() override
virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getProcedures(const css::uno::Any &catalog, const OUString &schemaPattern, const OUString &procedureNamePattern) override
virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getExportedKeys(const css::uno::Any &catalog, const OUString &schema, const OUString &table) override
virtual sal_Bool SAL_CALL supportsAlterTableWithDropColumn() override
virtual css::uno::Reference< css::sdbc::XConnection > SAL_CALL getConnection() override
virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getCatalogs() override
virtual bool impl_supportsMixedCaseQuotedIdentifiers_throw()=0
virtual bool impl_supportsAlterTableWithDropColumn_throw()=0
virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getSchemas() override
virtual sal_Bool SAL_CALL supportsMixedCaseQuotedIdentifiers() override
virtual sal_Bool SAL_CALL supportsSchemasInDataManipulation() override
virtual bool impl_supportsCatalogsInTableDefinitions_throw()=0
std::pair< bool, OUString > m_sCatalogSeparator
std::pair< bool, bool > m_supportsSchemasInTableDefinitions
virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getIndexInfo(const css::uno::Any &catalog, const OUString &schema, const OUString &table, sal_Bool unique, sal_Bool approximate) override
std::pair< bool, bool > m_supportsSchemasInDataManipulation
std::pair< bool, bool > m_supportsAlterTableWithDropColumn
virtual sal_Int32 SAL_CALL getMaxTablesInSelect() override
virtual bool impl_isCatalogAtStart_throw()=0
virtual sal_Bool SAL_CALL supportsCatalogsInTableDefinitions() override
std::pair< bool, bool > m_storesMixedCaseQuotedIdentifiers
::connectivity::ODatabaseMetaDataResultSet::ORows m_aTypeInfoRows
virtual sal_Int32 SAL_CALL getMaxStatements() override
std::pair< bool, bool > m_supportsMixedCaseQuotedIdentifiers
virtual sal_Int32 impl_getMaxTablesInSelect_throw()=0
virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getImportedKeys(const css::uno::Any &catalog, const OUString &schema, const OUString &table) override
virtual sal_Bool SAL_CALL storesMixedCaseQuotedIdentifiers() override
virtual bool impl_supportsCatalogsInDataManipulation_throw()=0
T callImplMethod(std::pair< bool, T > &_rCache, const std::function< T(ODatabaseMetaDataBase *)> &_pImplMethod)
virtual OUString SAL_CALL getIdentifierQuoteString() override
virtual OUString impl_getIdentifierQuoteString_throw()=0
css::uno::Reference< css::sdbc::XConnection > m_xConnection
virtual OUString SAL_CALL getCatalogSeparator() override
std::pair< bool, bool > m_supportsAlterTableWithAddColumn
virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getBestRowIdentifier(const css::uno::Any &catalog, const OUString &schema, const OUString &table, sal_Int32 scope, sal_Bool nullable) override
virtual bool impl_storesMixedCaseQuotedIdentifiers_throw()=0
virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getTablePrivileges(const css::uno::Any &catalog, const OUString &schemaPattern, const OUString &tableNamePattern) override
virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getColumnPrivileges(const css::uno::Any &catalog, const OUString &schema, const OUString &table, const OUString &columnNamePattern) override
virtual bool impl_supportsAlterTableWithAddColumn_throw()=0
std::pair< bool, bool > m_supportsCatalogsInDataManipulation
virtual bool impl_supportsSchemasInDataManipulation_throw()=0
virtual OUString impl_getCatalogSeparator_throw()=0
virtual sal_Bool SAL_CALL supportsCatalogsInDataManipulation() override
virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getTypeInfo() override
virtual css::uno::Reference< css::sdbc::XResultSet > impl_getTypeInfo_throw()=0
static ORowSetValueDecoratorRef const & getEmptyValue()
return an empty ORowSetValueDecorator
std::vector< ORowSetValueDecoratorRef > ORow
@ eVersionColumns
describes a result set as expected by XDatabaseMetaData::getVersionColumns
@ ePrimaryKeys
describes a result set as expected by XDatabaseMetaData::getPrimaryKeys
@ eIndexInfo
describes a result set as expected by XDatabaseMetaData::getIndexInfo
@ eImportedKeys
describes a result set as expected by XDatabaseMetaData::getImportedKeys
@ eTypeInfo
describes a result set as expected by XDatabaseMetaData::getTypeInfo
@ eSchemas
describes a result set as expected by XDatabaseMetaData::getSchemas
@ eColumnPrivileges
describes a result set as expected by XDatabaseMetaData::getColumnPrivileges
@ eProcedures
describes a result set as expected by XDatabaseMetaData::getProcedures
@ eCrossReference
describes a result set as expected by XDatabaseMetaData::getCrossReference
@ eExportedKeys
describes a result set as expected by XDatabaseMetaData::getExportedKeys
@ eBestRowIdentifier
describes a result set as expected by XDatabaseMetaData::getBestRowIdentifier
@ eCatalogs
describes a result set as expected by XDatabaseMetaData::getCatalogs
@ eProcedureColumns
describes a result set as expected by XDatabaseMetaData::getProcedureColumns
@ eTablePrivileges
describes a result set as expected by XDatabaseMetaData::getTablePrivileges
ORowSetValueDecorator decorates an ORowSetValue so the value is "refcounted".
Definition: FValue.hxx:402
void fill(sal_Int32 _nPos, sal_Int32 _nType, const css::uno::Reference< css::sdbc::XRow > &_xRow)
fetches a single value out of the row
Definition: FValue.cxx:2215
helper class for accessing resources shared by different libraries in the connectivity module
OUString getResourceString(TranslateId pResId) const
loads a string from the shared resource file
mutable::osl::Mutex m_aMutex
ULONG m_refCount
void throwGenericSQLException(const OUString &_rMsg, const css::uno::Reference< css::uno::XInterface > &_rxSource)
throw a generic SQLException, i.e.
int i
HashMap_OWString_Interface aMap
Reference< XConnection > m_xConnection
This exception is thrown, when the arithmetic expression parser failed to parse a string.
unsigned char sal_Bool