update credits
[LibreOffice.git] / connectivity / source / commontools / TDatabaseMetaDataBase.cxx
blob9918cf15839a31fb18d2bbb1a1529e52324e19d7
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "TDatabaseMetaDataBase.hxx"
21 #include "RowFunctionParser.hxx"
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>
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::beans;
35 using namespace comphelper;
36 using namespace connectivity;
39 ODatabaseMetaDataBase::ODatabaseMetaDataBase(const Reference< XConnection >& _rxConnection,const Sequence< PropertyValue >& _rInfo)
40 : m_aConnectionInfo(_rInfo)
41 ,m_isCatalogAtStart(false,sal_False)
42 ,m_sCatalogSeparator(false,OUString())
43 ,m_sIdentifierQuoteString(false,OUString())
44 ,m_supportsCatalogsInTableDefinitions(false,sal_False)
45 ,m_supportsSchemasInTableDefinitions(false,sal_False)
46 ,m_supportsCatalogsInDataManipulation(false,sal_False)
47 ,m_supportsSchemasInDataManipulation(false,sal_False)
48 ,m_supportsMixedCaseQuotedIdentifiers(false,sal_False)
49 ,m_supportsAlterTableWithAddColumn(false,sal_False)
50 ,m_supportsAlterTableWithDropColumn(false,sal_False)
51 ,m_MaxStatements(false,0)
52 ,m_MaxTablesInSelect(false,0)
53 ,m_storesMixedCaseQuotedIdentifiers(false,sal_False)
54 , m_xConnection(_rxConnection)
56 osl_atomic_increment( &m_refCount );
58 m_xListenerHelper = new OEventListenerHelper(this);
59 Reference<XComponent> xCom(m_xConnection,UNO_QUERY);
60 if(xCom.is())
61 xCom->addEventListener(m_xListenerHelper);
63 osl_atomic_decrement( &m_refCount );
65 // -------------------------------------------------------------------------
66 ODatabaseMetaDataBase::~ODatabaseMetaDataBase()
70 // -----------------------------------------------------------------------------
71 Sequence< PropertyValue > SAL_CALL ODatabaseMetaDataBase::getConnectionInfo( ) throw (RuntimeException)
73 return m_aConnectionInfo;
76 // -----------------------------------------------------------------------------
77 void SAL_CALL ODatabaseMetaDataBase::disposing( const EventObject& /*Source*/ ) throw(RuntimeException)
79 // cut off all references to the connection
80 m_xConnection.clear();
81 m_xListenerHelper.clear();
83 // -----------------------------------------------------------------------------
84 Reference< XResultSet > SAL_CALL ODatabaseMetaDataBase::getTypeInfo( ) throw(SQLException, RuntimeException)
86 ::osl::MutexGuard aGuard( m_aMutex );
87 if ( m_aTypeInfoRows.empty() )
89 Reference< XResultSet > xRet = impl_getTypeInfo_throw();
90 Reference< XRow > xRow(xRet,UNO_QUERY);
91 ::comphelper::SequenceAsHashMap aMap(m_aConnectionInfo);
92 Sequence< Any > aTypeInfoSettings;
93 aTypeInfoSettings = aMap.getUnpackedValueOrDefault(OUString("TypeInfoSettings"),aTypeInfoSettings);
95 if ( xRow.is() )
97 static sal_Int32 pTypes[] = {
98 DataType::VARCHAR
99 ,DataType::INTEGER
100 ,DataType::INTEGER
101 ,DataType::VARCHAR
102 ,DataType::VARCHAR
103 ,DataType::VARCHAR
104 ,DataType::INTEGER
105 ,DataType::BOOLEAN
106 ,DataType::INTEGER
107 ,DataType::BOOLEAN
108 ,DataType::BOOLEAN
109 ,DataType::BOOLEAN
110 ,DataType::VARCHAR
111 ,DataType::INTEGER
112 ,DataType::INTEGER
113 ,DataType::INTEGER
114 ,DataType::INTEGER
115 ,DataType::INTEGER
117 ::std::vector<ExpressionNodeSharedPtr> aConditions;
118 if ( aTypeInfoSettings.getLength() > 1 && ((aTypeInfoSettings.getLength() % 2) == 0) )
120 const Any* pIter = aTypeInfoSettings.getConstArray();
121 const Any* pEnd = pIter + aTypeInfoSettings.getLength();
124 for(;pIter != pEnd;++pIter)
125 aConditions.push_back(FunctionParser::parseFunction(::comphelper::getString(*pIter)));
127 catch(ParseError&)
129 ::connectivity::SharedResources aResources;
130 const OUString sError( aResources.getResourceString(STR_FORMULA_WRONG));
131 ::dbtools::throwGenericSQLException(sError,*this);
135 ::connectivity::ODatabaseMetaDataResultSet::ORows aTypeInfoRows;
136 while( xRet->next() )
138 ::connectivity::ODatabaseMetaDataResultSet::ORow aRow;
139 aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue());
140 sal_Int32* pType = pTypes;
141 for (sal_Int32 i = 1; i <= sal_Int32(sizeof(pTypes)/sizeof(pTypes[0])); ++i,++pType)
143 ORowSetValue aValue;
144 aValue.fill(i,*pType,xRow);
145 aRow.push_back(new ORowSetValueDecorator(aValue));
148 ::std::vector<ExpressionNodeSharedPtr>::iterator aIter = aConditions.begin();
149 ::std::vector<ExpressionNodeSharedPtr>::iterator aEnd = aConditions.end();
150 for (; aIter != aEnd; ++aIter)
152 if ( (*aIter)->evaluate(aRow)->getValue().getBool() )
154 ++aIter;
155 (*aIter)->fill(aRow);
157 else
158 ++aIter;
160 aTypeInfoRows.push_back(aRow);
162 m_aTypeInfoRows = aTypeInfoRows;
165 ::connectivity::ODatabaseMetaDataResultSet* pResult = new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eTypeInfo);
166 Reference< XResultSet > xRet = pResult;
167 pResult->setRows(m_aTypeInfoRows);
168 return xRet;
170 // -------------------------------------------------------------------------
171 Reference< XResultSet > SAL_CALL ODatabaseMetaDataBase::getExportedKeys(
172 const Any& /*catalog*/, const OUString& /*schema*/, const OUString& /*table*/ ) throw(SQLException, RuntimeException)
174 return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eExportedKeys );
176 // -------------------------------------------------------------------------
177 Reference< XResultSet > SAL_CALL ODatabaseMetaDataBase::getImportedKeys(
178 const Any& /*catalog*/, const OUString& /*schema*/, const OUString& /*table*/ ) throw(SQLException, RuntimeException)
180 return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eImportedKeys );
182 // -------------------------------------------------------------------------
183 Reference< XResultSet > SAL_CALL ODatabaseMetaDataBase::getPrimaryKeys(
184 const Any& /*catalog*/, const OUString& /*schema*/, const OUString& /*table*/ ) throw(SQLException, RuntimeException)
186 return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::ePrimaryKeys );
188 // -------------------------------------------------------------------------
189 Reference< XResultSet > SAL_CALL ODatabaseMetaDataBase::getIndexInfo(
190 const Any& /*catalog*/, const OUString& /*schema*/, const OUString& /*table*/,
191 sal_Bool /*unique*/, sal_Bool /*approximate*/ ) throw(SQLException, RuntimeException)
193 return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eIndexInfo );
195 // -------------------------------------------------------------------------
196 Reference< XResultSet > SAL_CALL ODatabaseMetaDataBase::getBestRowIdentifier(
197 const Any& /*catalog*/, const OUString& /*schema*/, const OUString& /*table*/, sal_Int32 /*scope*/,
198 sal_Bool /*nullable*/ ) throw(SQLException, RuntimeException)
200 return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eBestRowIdentifier );
202 // -------------------------------------------------------------------------
203 Reference< XResultSet > SAL_CALL ODatabaseMetaDataBase::getCrossReference(
204 const Any& /*primaryCatalog*/, const OUString& /*primarySchema*/,
205 const OUString& /*primaryTable*/, const Any& /*foreignCatalog*/,
206 const OUString& /*foreignSchema*/, const OUString& /*foreignTable*/ ) throw(SQLException, RuntimeException)
208 return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eCrossReference );
210 // -------------------------------------------------------------------------
211 Reference< XConnection > SAL_CALL ODatabaseMetaDataBase::getConnection( ) throw(SQLException, RuntimeException)
213 return m_xConnection;
215 // -------------------------------------------------------------------------
216 Reference< XResultSet > SAL_CALL ODatabaseMetaDataBase::getProcedureColumns(
217 const Any& /*catalog*/, const OUString& /*schemaPattern*/,
218 const OUString& /*procedureNamePattern*/, const OUString& /*columnNamePattern*/ ) throw(SQLException, RuntimeException)
220 return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eProcedureColumns );
222 // -------------------------------------------------------------------------
223 Reference< XResultSet > SAL_CALL ODatabaseMetaDataBase::getProcedures(
224 const Any& /*catalog*/, const OUString& /*schemaPattern*/,
225 const OUString& /*procedureNamePattern*/ ) throw(SQLException, RuntimeException)
227 return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eProcedures );
229 // -------------------------------------------------------------------------
230 Reference< XResultSet > SAL_CALL ODatabaseMetaDataBase::getVersionColumns(
231 const Any& /*catalog*/, const OUString& /*schema*/, const OUString& /*table*/ ) throw(SQLException, RuntimeException)
233 return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eVersionColumns );
235 // -------------------------------------------------------------------------
236 Reference< XResultSet > SAL_CALL ODatabaseMetaDataBase::getSchemas( ) throw(SQLException, RuntimeException)
238 return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eSchemas );
240 // -------------------------------------------------------------------------
241 Reference< XResultSet > SAL_CALL ODatabaseMetaDataBase::getColumnPrivileges(
242 const Any& /*catalog*/, const OUString& /*schema*/, const OUString& /*table*/,
243 const OUString& /*columnNamePattern*/ ) throw(SQLException, RuntimeException)
245 return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eColumnPrivileges );
247 // -------------------------------------------------------------------------
248 Reference< XResultSet > SAL_CALL ODatabaseMetaDataBase::getTablePrivileges(
249 const Any& /*catalog*/, const OUString& /*schema*/, const OUString& /*table*/) throw(SQLException, RuntimeException)
251 return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eTablePrivileges );
253 // -------------------------------------------------------------------------
254 Reference< XResultSet > SAL_CALL ODatabaseMetaDataBase::getCatalogs( ) throw(SQLException, RuntimeException)
256 return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eCatalogs );
258 // -----------------------------------------------------------------------------
259 OUString SAL_CALL ODatabaseMetaDataBase::getIdentifierQuoteString( ) throw(SQLException, RuntimeException)
261 return callImplMethod(m_sIdentifierQuoteString,::std::mem_fun_t< OUString ,ODatabaseMetaDataBase>(&ODatabaseMetaDataBase::impl_getIdentifierQuoteString_throw));
263 // -----------------------------------------------------------------------------
264 sal_Bool SAL_CALL ODatabaseMetaDataBase::isCatalogAtStart( ) throw(SQLException, RuntimeException)
266 return callImplMethod(m_isCatalogAtStart,::std::mem_fun_t< sal_Bool,ODatabaseMetaDataBase>(&ODatabaseMetaDataBase::impl_isCatalogAtStart_throw));
268 // -----------------------------------------------------------------------------
269 OUString SAL_CALL ODatabaseMetaDataBase::getCatalogSeparator( ) throw(SQLException, RuntimeException)
271 return callImplMethod(m_sCatalogSeparator,::std::mem_fun_t< OUString,ODatabaseMetaDataBase>(&ODatabaseMetaDataBase::impl_getCatalogSeparator_throw));
273 // -----------------------------------------------------------------------------
274 sal_Bool SAL_CALL ODatabaseMetaDataBase::supportsCatalogsInTableDefinitions( ) throw(SQLException, RuntimeException)
276 return callImplMethod(m_supportsCatalogsInTableDefinitions,::std::mem_fun_t< sal_Bool,ODatabaseMetaDataBase>(&ODatabaseMetaDataBase::impl_supportsCatalogsInTableDefinitions_throw));
278 // -----------------------------------------------------------------------------
279 sal_Bool SAL_CALL ODatabaseMetaDataBase::supportsSchemasInTableDefinitions( ) throw(SQLException, RuntimeException)
281 return callImplMethod(m_supportsSchemasInTableDefinitions,::std::mem_fun_t< sal_Bool,ODatabaseMetaDataBase>(&ODatabaseMetaDataBase::impl_supportsSchemasInTableDefinitions_throw));
283 // -----------------------------------------------------------------------------
284 sal_Bool SAL_CALL ODatabaseMetaDataBase::supportsCatalogsInDataManipulation( ) throw(SQLException, RuntimeException)
286 return callImplMethod(m_supportsCatalogsInDataManipulation,::std::mem_fun_t< sal_Bool,ODatabaseMetaDataBase>(&ODatabaseMetaDataBase::impl_supportsCatalogsInDataManipulation_throw));
288 // -----------------------------------------------------------------------------
289 sal_Bool SAL_CALL ODatabaseMetaDataBase::supportsSchemasInDataManipulation( ) throw(SQLException, RuntimeException)
291 return callImplMethod(m_supportsSchemasInDataManipulation,::std::mem_fun_t< sal_Bool,ODatabaseMetaDataBase>(&ODatabaseMetaDataBase::impl_supportsSchemasInDataManipulation_throw));
293 // -----------------------------------------------------------------------------
294 sal_Bool SAL_CALL ODatabaseMetaDataBase::supportsMixedCaseQuotedIdentifiers( ) throw(SQLException, RuntimeException)
296 return callImplMethod(m_supportsMixedCaseQuotedIdentifiers,::std::mem_fun_t< sal_Bool,ODatabaseMetaDataBase>(&ODatabaseMetaDataBase::impl_supportsMixedCaseQuotedIdentifiers_throw));
298 // -----------------------------------------------------------------------------
299 sal_Bool SAL_CALL ODatabaseMetaDataBase::supportsAlterTableWithAddColumn( ) throw(SQLException, RuntimeException)
301 return callImplMethod(m_supportsAlterTableWithAddColumn,::std::mem_fun_t< sal_Bool,ODatabaseMetaDataBase>(&ODatabaseMetaDataBase::impl_supportsAlterTableWithAddColumn_throw));
303 // -----------------------------------------------------------------------------
304 sal_Bool SAL_CALL ODatabaseMetaDataBase::supportsAlterTableWithDropColumn( ) throw(SQLException, RuntimeException)
306 return callImplMethod(m_supportsAlterTableWithDropColumn,::std::mem_fun_t< sal_Bool,ODatabaseMetaDataBase>(&ODatabaseMetaDataBase::impl_supportsAlterTableWithDropColumn_throw));
308 // -----------------------------------------------------------------------------
309 sal_Int32 SAL_CALL ODatabaseMetaDataBase::getMaxStatements( ) throw(SQLException, RuntimeException)
311 return callImplMethod(m_MaxStatements,::std::mem_fun_t< sal_Int32,ODatabaseMetaDataBase>(&ODatabaseMetaDataBase::impl_getMaxStatements_throw));
313 // -----------------------------------------------------------------------------
314 sal_Int32 SAL_CALL ODatabaseMetaDataBase::getMaxTablesInSelect( ) throw(SQLException, RuntimeException)
316 return callImplMethod(m_MaxTablesInSelect,::std::mem_fun_t< sal_Int32,ODatabaseMetaDataBase>(&ODatabaseMetaDataBase::impl_getMaxTablesInSelect_throw));
318 // -----------------------------------------------------------------------------
319 sal_Bool SAL_CALL ODatabaseMetaDataBase::storesMixedCaseQuotedIdentifiers( ) throw(SQLException, RuntimeException)
321 return callImplMethod(m_storesMixedCaseQuotedIdentifiers,::std::mem_fun_t< sal_Bool,ODatabaseMetaDataBase>(&ODatabaseMetaDataBase::impl_storesMixedCaseQuotedIdentifiers_throw));
323 // -----------------------------------------------------------------------------
325 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */