Branch data Line data Source code
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 "TDatabaseMetaDataBase.hxx"
21 : : #include "RowFunctionParser.hxx"
22 : :
23 : : #include <comphelper/sequenceashashmap.hxx>
24 : : #include <comphelper/evtlistenerhlp.hxx>
25 : : #include <com/sun/star/lang/XComponent.hpp>
26 : : #include "resource/sharedresources.hxx"
27 : : #include "resource/common_res.hrc"
28 : : #include <connectivity/dbexception.hxx>
29 : : #include <sal/macros.h>
30 : :
31 : : using namespace com::sun::star::uno;
32 : : using namespace com::sun::star::lang;
33 : : using namespace com::sun::star::sdbc;
34 : : using namespace com::sun::star::lang;
35 : : using namespace com::sun::star::beans;
36 : : using namespace comphelper;
37 : : using namespace connectivity;
38 : :
39 : :
40 : 56 : ODatabaseMetaDataBase::ODatabaseMetaDataBase(const Reference< XConnection >& _rxConnection,const Sequence< PropertyValue >& _rInfo)
41 : : : m_aConnectionInfo(_rInfo)
42 : : ,m_isCatalogAtStart(false,sal_False)
43 : : ,m_sCatalogSeparator(false,::rtl::OUString())
44 : : ,m_sIdentifierQuoteString(false,::rtl::OUString())
45 : : ,m_supportsCatalogsInTableDefinitions(false,sal_False)
46 : : ,m_supportsSchemasInTableDefinitions(false,sal_False)
47 : : ,m_supportsCatalogsInDataManipulation(false,sal_False)
48 : : ,m_supportsSchemasInDataManipulation(false,sal_False)
49 : : ,m_supportsMixedCaseQuotedIdentifiers(false,sal_False)
50 : : ,m_supportsAlterTableWithAddColumn(false,sal_False)
51 : : ,m_supportsAlterTableWithDropColumn(false,sal_False)
52 : : ,m_MaxStatements(false,0)
53 : : ,m_MaxTablesInSelect(false,0)
54 : : ,m_storesMixedCaseQuotedIdentifiers(false,sal_False)
55 [ + - ][ + - ]: 56 : , m_xConnection(_rxConnection)
[ + - ]
56 : : {
57 [ + - ]: 56 : osl_incrementInterlockedCount( &m_refCount );
58 : : {
59 [ + - ][ + - ]: 56 : m_xListenerHelper = new OEventListenerHelper(this);
[ + - ][ + - ]
60 [ + - ]: 56 : Reference<XComponent> xCom(m_xConnection,UNO_QUERY);
61 [ + - ]: 56 : if(xCom.is())
62 [ + - ][ + - ]: 56 : xCom->addEventListener(m_xListenerHelper);
63 : : }
64 [ + - ]: 56 : osl_decrementInterlockedCount( &m_refCount );
65 : 56 : }
66 : : // -------------------------------------------------------------------------
67 [ + - ][ + - ]: 56 : ODatabaseMetaDataBase::~ODatabaseMetaDataBase()
68 : : {
69 [ - + ]: 56 : }
70 : :
71 : : // -----------------------------------------------------------------------------
72 : 0 : Sequence< PropertyValue > SAL_CALL ODatabaseMetaDataBase::getConnectionInfo( ) throw (RuntimeException)
73 : : {
74 : 0 : return m_aConnectionInfo;
75 : : }
76 : :
77 : : // -----------------------------------------------------------------------------
78 : 26 : void SAL_CALL ODatabaseMetaDataBase::disposing( const EventObject& /*Source*/ ) throw(RuntimeException)
79 : : {
80 : : // cut off all references to the connection
81 : 26 : m_xConnection.clear();
82 : 26 : m_xListenerHelper.clear();
83 : 26 : }
84 : : // -----------------------------------------------------------------------------
85 : 6 : Reference< XResultSet > SAL_CALL ODatabaseMetaDataBase::getTypeInfo( ) throw(SQLException, RuntimeException)
86 : : {
87 [ + - ]: 6 : ::osl::MutexGuard aGuard( m_aMutex );
88 [ + + ]: 6 : if ( m_aTypeInfoRows.empty() )
89 : : {
90 [ + - ]: 2 : Reference< XResultSet > xRet = impl_getTypeInfo_throw();
91 [ + - ]: 2 : Reference< XRow > xRow(xRet,UNO_QUERY);
92 [ + - ]: 2 : ::comphelper::SequenceAsHashMap aMap(m_aConnectionInfo);
93 [ + - ]: 2 : Sequence< Any > aTypeInfoSettings;
94 [ + - ][ + - ]: 2 : aTypeInfoSettings = aMap.getUnpackedValueOrDefault(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TypeInfoSettings")),aTypeInfoSettings);
[ + - ][ + - ]
95 : :
96 [ + - ]: 2 : if ( xRow.is() )
97 : : {
98 : : static sal_Int32 pTypes[] = {
99 : : DataType::VARCHAR
100 : : ,DataType::INTEGER
101 : : ,DataType::INTEGER
102 : : ,DataType::VARCHAR
103 : : ,DataType::VARCHAR
104 : : ,DataType::VARCHAR
105 : : ,DataType::INTEGER
106 : : ,DataType::BOOLEAN
107 : : ,DataType::INTEGER
108 : : ,DataType::BOOLEAN
109 : : ,DataType::BOOLEAN
110 : : ,DataType::BOOLEAN
111 : : ,DataType::VARCHAR
112 : : ,DataType::INTEGER
113 : : ,DataType::INTEGER
114 : : ,DataType::INTEGER
115 : : ,DataType::INTEGER
116 : : ,DataType::INTEGER
117 : : };
118 [ + - ]: 2 : ::std::vector<ExpressionNodeSharedPtr> aConditions;
119 [ - + ][ # # ]: 2 : if ( aTypeInfoSettings.getLength() > 1 && ((aTypeInfoSettings.getLength() % 2) == 0) )
[ - + ]
120 : : {
121 : 0 : const Any* pIter = aTypeInfoSettings.getConstArray();
122 : 0 : const Any* pEnd = pIter + aTypeInfoSettings.getLength();
123 : : try
124 : : {
125 [ # # ]: 0 : for(;pIter != pEnd;++pIter)
126 [ # # ][ # # ]: 0 : aConditions.push_back(FunctionParser::parseFunction(::comphelper::getString(*pIter)));
[ # # ][ # # ]
127 : : }
128 [ # # ]: 0 : catch(ParseError&)
129 : : {
130 [ # # ]: 0 : ::connectivity::SharedResources aResources;
131 [ # # ]: 0 : const ::rtl::OUString sError( aResources.getResourceString(STR_FORMULA_WRONG));
132 [ # # # # : 0 : ::dbtools::throwGenericSQLException(sError,*this);
# # ]
133 : : }
134 : : }
135 : :
136 [ + - ]: 2 : ::connectivity::ODatabaseMetaDataResultSet::ORows aTypeInfoRows;
137 [ + - ][ + - ]: 22 : while( xRet->next() )
[ + + ]
138 : : {
139 [ + - ]: 20 : ::connectivity::ODatabaseMetaDataResultSet::ORow aRow;
140 [ + - ][ + - ]: 20 : aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue());
[ + - ]
141 : 20 : sal_Int32* pType = pTypes;
142 [ + + ]: 380 : for (sal_Int32 i = 1; i <= sal_Int32(sizeof(pTypes)/sizeof(pTypes[0])); ++i,++pType)
143 : : {
144 : 360 : ORowSetValue aValue;
145 [ + - ]: 360 : aValue.fill(i,*pType,xRow);
146 [ + - ][ + - ]: 360 : aRow.push_back(new ORowSetValueDecorator(aValue));
[ + - ][ + - ]
[ + - ]
147 [ + - ]: 360 : }
148 : :
149 : 20 : ::std::vector<ExpressionNodeSharedPtr>::iterator aIter = aConditions.begin();
150 : 20 : ::std::vector<ExpressionNodeSharedPtr>::iterator aEnd = aConditions.end();
151 [ + - ][ - + ]: 20 : for (; aIter != aEnd; ++aIter)
152 : : {
153 [ # # ][ # # ]: 0 : if ( (*aIter)->evaluate(aRow)->getValue().getBool() )
[ # # ][ # # ]
154 : : {
155 : 0 : ++aIter;
156 [ # # ]: 0 : (*aIter)->fill(aRow);
157 : : }
158 : : else
159 : 0 : ++aIter;
160 : : }
161 [ + - ]: 20 : aTypeInfoRows.push_back(aRow);
162 : 20 : }
163 [ + - ]: 2 : m_aTypeInfoRows = aTypeInfoRows;
164 [ + - ][ + - ]: 2 : }
165 : : }
166 [ + - ]: 6 : ::connectivity::ODatabaseMetaDataResultSet* pResult = new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eTypeInfo);
167 [ + - ][ + - ]: 6 : Reference< XResultSet > xRet = pResult;
168 [ + - ]: 6 : pResult->setRows(m_aTypeInfoRows);
169 [ + - ]: 6 : return xRet;
170 : : }
171 : : // -------------------------------------------------------------------------
172 : 0 : Reference< XResultSet > SAL_CALL ODatabaseMetaDataBase::getExportedKeys(
173 : : const Any& /*catalog*/, const ::rtl::OUString& /*schema*/, const ::rtl::OUString& /*table*/ ) throw(SQLException, RuntimeException)
174 : : {
175 [ # # ][ # # ]: 0 : return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eExportedKeys );
176 : : }
177 : : // -------------------------------------------------------------------------
178 : 0 : Reference< XResultSet > SAL_CALL ODatabaseMetaDataBase::getImportedKeys(
179 : : const Any& /*catalog*/, const ::rtl::OUString& /*schema*/, const ::rtl::OUString& /*table*/ ) throw(SQLException, RuntimeException)
180 : : {
181 [ # # ][ # # ]: 0 : return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eImportedKeys );
182 : : }
183 : : // -------------------------------------------------------------------------
184 : 0 : Reference< XResultSet > SAL_CALL ODatabaseMetaDataBase::getPrimaryKeys(
185 : : const Any& /*catalog*/, const ::rtl::OUString& /*schema*/, const ::rtl::OUString& /*table*/ ) throw(SQLException, RuntimeException)
186 : : {
187 [ # # ][ # # ]: 0 : return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::ePrimaryKeys );
188 : : }
189 : : // -------------------------------------------------------------------------
190 : 0 : Reference< XResultSet > SAL_CALL ODatabaseMetaDataBase::getIndexInfo(
191 : : const Any& /*catalog*/, const ::rtl::OUString& /*schema*/, const ::rtl::OUString& /*table*/,
192 : : sal_Bool /*unique*/, sal_Bool /*approximate*/ ) throw(SQLException, RuntimeException)
193 : : {
194 [ # # ][ # # ]: 0 : return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eIndexInfo );
195 : : }
196 : : // -------------------------------------------------------------------------
197 : 0 : Reference< XResultSet > SAL_CALL ODatabaseMetaDataBase::getBestRowIdentifier(
198 : : const Any& /*catalog*/, const ::rtl::OUString& /*schema*/, const ::rtl::OUString& /*table*/, sal_Int32 /*scope*/,
199 : : sal_Bool /*nullable*/ ) throw(SQLException, RuntimeException)
200 : : {
201 [ # # ][ # # ]: 0 : return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eBestRowIdentifier );
202 : : }
203 : : // -------------------------------------------------------------------------
204 : 0 : Reference< XResultSet > SAL_CALL ODatabaseMetaDataBase::getCrossReference(
205 : : const Any& /*primaryCatalog*/, const ::rtl::OUString& /*primarySchema*/,
206 : : const ::rtl::OUString& /*primaryTable*/, const Any& /*foreignCatalog*/,
207 : : const ::rtl::OUString& /*foreignSchema*/, const ::rtl::OUString& /*foreignTable*/ ) throw(SQLException, RuntimeException)
208 : : {
209 [ # # ][ # # ]: 0 : return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eCrossReference );
210 : : }
211 : : // -------------------------------------------------------------------------
212 : 0 : Reference< XConnection > SAL_CALL ODatabaseMetaDataBase::getConnection( ) throw(SQLException, RuntimeException)
213 : : {
214 : 0 : return m_xConnection;
215 : : }
216 : : // -------------------------------------------------------------------------
217 : 0 : Reference< XResultSet > SAL_CALL ODatabaseMetaDataBase::getProcedureColumns(
218 : : const Any& /*catalog*/, const ::rtl::OUString& /*schemaPattern*/,
219 : : const ::rtl::OUString& /*procedureNamePattern*/, const ::rtl::OUString& /*columnNamePattern*/ ) throw(SQLException, RuntimeException)
220 : : {
221 [ # # ][ # # ]: 0 : return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eProcedureColumns );
222 : : }
223 : : // -------------------------------------------------------------------------
224 : 0 : Reference< XResultSet > SAL_CALL ODatabaseMetaDataBase::getProcedures(
225 : : const Any& /*catalog*/, const ::rtl::OUString& /*schemaPattern*/,
226 : : const ::rtl::OUString& /*procedureNamePattern*/ ) throw(SQLException, RuntimeException)
227 : : {
228 [ # # ][ # # ]: 0 : return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eProcedures );
229 : : }
230 : : // -------------------------------------------------------------------------
231 : 62 : Reference< XResultSet > SAL_CALL ODatabaseMetaDataBase::getVersionColumns(
232 : : const Any& /*catalog*/, const ::rtl::OUString& /*schema*/, const ::rtl::OUString& /*table*/ ) throw(SQLException, RuntimeException)
233 : : {
234 [ + - ][ + - ]: 62 : return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eVersionColumns );
235 : : }
236 : : // -------------------------------------------------------------------------
237 : 0 : Reference< XResultSet > SAL_CALL ODatabaseMetaDataBase::getSchemas( ) throw(SQLException, RuntimeException)
238 : : {
239 [ # # ][ # # ]: 0 : return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eSchemas );
240 : : }
241 : : // -------------------------------------------------------------------------
242 : 0 : Reference< XResultSet > SAL_CALL ODatabaseMetaDataBase::getColumnPrivileges(
243 : : const Any& /*catalog*/, const ::rtl::OUString& /*schema*/, const ::rtl::OUString& /*table*/,
244 : : const ::rtl::OUString& /*columnNamePattern*/ ) throw(SQLException, RuntimeException)
245 : : {
246 [ # # ][ # # ]: 0 : return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eColumnPrivileges );
247 : : }
248 : : // -------------------------------------------------------------------------
249 : 0 : Reference< XResultSet > SAL_CALL ODatabaseMetaDataBase::getTablePrivileges(
250 : : const Any& /*catalog*/, const ::rtl::OUString& /*schema*/, const ::rtl::OUString& /*table*/) throw(SQLException, RuntimeException)
251 : : {
252 [ # # ][ # # ]: 0 : return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eTablePrivileges );
253 : : }
254 : : // -------------------------------------------------------------------------
255 : 0 : Reference< XResultSet > SAL_CALL ODatabaseMetaDataBase::getCatalogs( ) throw(SQLException, RuntimeException)
256 : : {
257 [ # # ][ # # ]: 0 : return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eCatalogs );
258 : : }
259 : : // -----------------------------------------------------------------------------
260 : 3098 : ::rtl::OUString SAL_CALL ODatabaseMetaDataBase::getIdentifierQuoteString( ) throw(SQLException, RuntimeException)
261 : : {
262 [ + - ]: 3098 : return callImplMethod(m_sIdentifierQuoteString,::std::mem_fun_t< ::rtl::OUString ,ODatabaseMetaDataBase>(&ODatabaseMetaDataBase::impl_getIdentifierQuoteString_throw));
263 : : }
264 : : // -----------------------------------------------------------------------------
265 : 0 : sal_Bool SAL_CALL ODatabaseMetaDataBase::isCatalogAtStart( ) throw(SQLException, RuntimeException)
266 : : {
267 [ # # ]: 0 : return callImplMethod(m_isCatalogAtStart,::std::mem_fun_t< sal_Bool,ODatabaseMetaDataBase>(&ODatabaseMetaDataBase::impl_isCatalogAtStart_throw));
268 : : }
269 : : // -----------------------------------------------------------------------------
270 : 6456 : ::rtl::OUString SAL_CALL ODatabaseMetaDataBase::getCatalogSeparator( ) throw(SQLException, RuntimeException)
271 : : {
272 [ + - ]: 6456 : return callImplMethod(m_sCatalogSeparator,::std::mem_fun_t< ::rtl::OUString,ODatabaseMetaDataBase>(&ODatabaseMetaDataBase::impl_getCatalogSeparator_throw));
273 : : }
274 : : // -----------------------------------------------------------------------------
275 : 0 : sal_Bool SAL_CALL ODatabaseMetaDataBase::supportsCatalogsInTableDefinitions( ) throw(SQLException, RuntimeException)
276 : : {
277 [ # # ]: 0 : return callImplMethod(m_supportsCatalogsInTableDefinitions,::std::mem_fun_t< sal_Bool,ODatabaseMetaDataBase>(&ODatabaseMetaDataBase::impl_supportsCatalogsInTableDefinitions_throw));
278 : : }
279 : : // -----------------------------------------------------------------------------
280 : 0 : sal_Bool SAL_CALL ODatabaseMetaDataBase::supportsSchemasInTableDefinitions( ) throw(SQLException, RuntimeException)
281 : : {
282 [ # # ]: 0 : return callImplMethod(m_supportsSchemasInTableDefinitions,::std::mem_fun_t< sal_Bool,ODatabaseMetaDataBase>(&ODatabaseMetaDataBase::impl_supportsSchemasInTableDefinitions_throw));
283 : : }
284 : : // -----------------------------------------------------------------------------
285 : 1300 : sal_Bool SAL_CALL ODatabaseMetaDataBase::supportsCatalogsInDataManipulation( ) throw(SQLException, RuntimeException)
286 : : {
287 [ + - ]: 1300 : return callImplMethod(m_supportsCatalogsInDataManipulation,::std::mem_fun_t< sal_Bool,ODatabaseMetaDataBase>(&ODatabaseMetaDataBase::impl_supportsCatalogsInDataManipulation_throw));
288 : : }
289 : : // -----------------------------------------------------------------------------
290 : 1300 : sal_Bool SAL_CALL ODatabaseMetaDataBase::supportsSchemasInDataManipulation( ) throw(SQLException, RuntimeException)
291 : : {
292 [ + - ]: 1300 : return callImplMethod(m_supportsSchemasInDataManipulation,::std::mem_fun_t< sal_Bool,ODatabaseMetaDataBase>(&ODatabaseMetaDataBase::impl_supportsSchemasInDataManipulation_throw));
293 : : }
294 : : // -----------------------------------------------------------------------------
295 : 1058 : sal_Bool SAL_CALL ODatabaseMetaDataBase::supportsMixedCaseQuotedIdentifiers( ) throw(SQLException, RuntimeException)
296 : : {
297 [ + - ]: 1058 : return callImplMethod(m_supportsMixedCaseQuotedIdentifiers,::std::mem_fun_t< sal_Bool,ODatabaseMetaDataBase>(&ODatabaseMetaDataBase::impl_supportsMixedCaseQuotedIdentifiers_throw));
298 : : }
299 : : // -----------------------------------------------------------------------------
300 : 0 : sal_Bool SAL_CALL ODatabaseMetaDataBase::supportsAlterTableWithAddColumn( ) throw(SQLException, RuntimeException)
301 : : {
302 [ # # ]: 0 : return callImplMethod(m_supportsAlterTableWithAddColumn,::std::mem_fun_t< sal_Bool,ODatabaseMetaDataBase>(&ODatabaseMetaDataBase::impl_supportsAlterTableWithAddColumn_throw));
303 : : }
304 : : // -----------------------------------------------------------------------------
305 : 0 : sal_Bool SAL_CALL ODatabaseMetaDataBase::supportsAlterTableWithDropColumn( ) throw(SQLException, RuntimeException)
306 : : {
307 [ # # ]: 0 : return callImplMethod(m_supportsAlterTableWithDropColumn,::std::mem_fun_t< sal_Bool,ODatabaseMetaDataBase>(&ODatabaseMetaDataBase::impl_supportsAlterTableWithDropColumn_throw));
308 : : }
309 : : // -----------------------------------------------------------------------------
310 : 0 : sal_Int32 SAL_CALL ODatabaseMetaDataBase::getMaxStatements( ) throw(SQLException, RuntimeException)
311 : : {
312 [ # # ]: 0 : return callImplMethod(m_MaxStatements,::std::mem_fun_t< sal_Int32,ODatabaseMetaDataBase>(&ODatabaseMetaDataBase::impl_getMaxStatements_throw));
313 : : }
314 : : // -----------------------------------------------------------------------------
315 : 450 : sal_Int32 SAL_CALL ODatabaseMetaDataBase::getMaxTablesInSelect( ) throw(SQLException, RuntimeException)
316 : : {
317 [ + - ]: 450 : return callImplMethod(m_MaxTablesInSelect,::std::mem_fun_t< sal_Int32,ODatabaseMetaDataBase>(&ODatabaseMetaDataBase::impl_getMaxTablesInSelect_throw));
318 : : }
319 : : // -----------------------------------------------------------------------------
320 : 0 : sal_Bool SAL_CALL ODatabaseMetaDataBase::storesMixedCaseQuotedIdentifiers( ) throw(SQLException, RuntimeException)
321 : : {
322 [ # # ]: 0 : return callImplMethod(m_storesMixedCaseQuotedIdentifiers,::std::mem_fun_t< sal_Bool,ODatabaseMetaDataBase>(&ODatabaseMetaDataBase::impl_storesMixedCaseQuotedIdentifiers_throw));
323 : : }
324 : : // -----------------------------------------------------------------------------
325 : :
326 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|