Bump for 3.6-28
[LibreOffice.git] / connectivity / source / commontools / TDatabaseMetaDataBase.cxx
blob0c97c09a478a4d446b6946c34f634034f14e530b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include "TDatabaseMetaDataBase.hxx"
30 #include "RowFunctionParser.hxx"
32 #include <comphelper/sequenceashashmap.hxx>
33 #include <comphelper/evtlistenerhlp.hxx>
34 #include <com/sun/star/lang/XComponent.hpp>
35 #include "resource/sharedresources.hxx"
36 #include "resource/common_res.hrc"
37 #include <connectivity/dbexception.hxx>
38 #include <sal/macros.h>
40 using namespace com::sun::star::uno;
41 using namespace com::sun::star::lang;
42 using namespace com::sun::star::sdbc;
43 using namespace com::sun::star::lang;
44 using namespace com::sun::star::beans;
45 using namespace comphelper;
46 using namespace connectivity;
49 ODatabaseMetaDataBase::ODatabaseMetaDataBase(const Reference< XConnection >& _rxConnection,const Sequence< PropertyValue >& _rInfo)
50 : m_aConnectionInfo(_rInfo)
51 ,m_isCatalogAtStart(false,sal_False)
52 ,m_sCatalogSeparator(false,::rtl::OUString())
53 ,m_sIdentifierQuoteString(false,::rtl::OUString())
54 ,m_supportsCatalogsInTableDefinitions(false,sal_False)
55 ,m_supportsSchemasInTableDefinitions(false,sal_False)
56 ,m_supportsCatalogsInDataManipulation(false,sal_False)
57 ,m_supportsSchemasInDataManipulation(false,sal_False)
58 ,m_supportsMixedCaseQuotedIdentifiers(false,sal_False)
59 ,m_supportsAlterTableWithAddColumn(false,sal_False)
60 ,m_supportsAlterTableWithDropColumn(false,sal_False)
61 ,m_MaxStatements(false,0)
62 ,m_MaxTablesInSelect(false,0)
63 ,m_storesMixedCaseQuotedIdentifiers(false,sal_False)
64 , m_xConnection(_rxConnection)
66 osl_incrementInterlockedCount( &m_refCount );
68 m_xListenerHelper = new OEventListenerHelper(this);
69 Reference<XComponent> xCom(m_xConnection,UNO_QUERY);
70 if(xCom.is())
71 xCom->addEventListener(m_xListenerHelper);
73 osl_decrementInterlockedCount( &m_refCount );
75 // -------------------------------------------------------------------------
76 ODatabaseMetaDataBase::~ODatabaseMetaDataBase()
80 // -----------------------------------------------------------------------------
81 Sequence< PropertyValue > SAL_CALL ODatabaseMetaDataBase::getConnectionInfo( ) throw (RuntimeException)
83 return m_aConnectionInfo;
86 // -----------------------------------------------------------------------------
87 void SAL_CALL ODatabaseMetaDataBase::disposing( const EventObject& /*Source*/ ) throw(RuntimeException)
89 // cut off all references to the connection
90 m_xConnection.clear();
91 m_xListenerHelper.clear();
93 // -----------------------------------------------------------------------------
94 Reference< XResultSet > SAL_CALL ODatabaseMetaDataBase::getTypeInfo( ) throw(SQLException, RuntimeException)
96 ::osl::MutexGuard aGuard( m_aMutex );
97 if ( m_aTypeInfoRows.empty() )
99 Reference< XResultSet > xRet = impl_getTypeInfo_throw();
100 Reference< XRow > xRow(xRet,UNO_QUERY);
101 ::comphelper::SequenceAsHashMap aMap(m_aConnectionInfo);
102 Sequence< Any > aTypeInfoSettings;
103 aTypeInfoSettings = aMap.getUnpackedValueOrDefault(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TypeInfoSettings")),aTypeInfoSettings);
105 if ( xRow.is() )
107 static sal_Int32 pTypes[] = {
108 DataType::VARCHAR
109 ,DataType::INTEGER
110 ,DataType::INTEGER
111 ,DataType::VARCHAR
112 ,DataType::VARCHAR
113 ,DataType::VARCHAR
114 ,DataType::INTEGER
115 ,DataType::BOOLEAN
116 ,DataType::INTEGER
117 ,DataType::BOOLEAN
118 ,DataType::BOOLEAN
119 ,DataType::BOOLEAN
120 ,DataType::VARCHAR
121 ,DataType::INTEGER
122 ,DataType::INTEGER
123 ,DataType::INTEGER
124 ,DataType::INTEGER
125 ,DataType::INTEGER
127 ::std::vector<ExpressionNodeSharedPtr> aConditions;
128 if ( aTypeInfoSettings.getLength() > 1 && ((aTypeInfoSettings.getLength() % 2) == 0) )
130 const Any* pIter = aTypeInfoSettings.getConstArray();
131 const Any* pEnd = pIter + aTypeInfoSettings.getLength();
134 for(;pIter != pEnd;++pIter)
135 aConditions.push_back(FunctionParser::parseFunction(::comphelper::getString(*pIter)));
137 catch(ParseError&)
139 ::connectivity::SharedResources aResources;
140 const ::rtl::OUString sError( aResources.getResourceString(STR_FORMULA_WRONG));
141 ::dbtools::throwGenericSQLException(sError,*this);
145 ::connectivity::ODatabaseMetaDataResultSet::ORows aTypeInfoRows;
146 while( xRet->next() )
148 ::connectivity::ODatabaseMetaDataResultSet::ORow aRow;
149 aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue());
150 sal_Int32* pType = pTypes;
151 for (sal_Int32 i = 1; i <= sal_Int32(sizeof(pTypes)/sizeof(pTypes[0])); ++i,++pType)
153 ORowSetValue aValue;
154 aValue.fill(i,*pType,xRow);
155 aRow.push_back(new ORowSetValueDecorator(aValue));
158 ::std::vector<ExpressionNodeSharedPtr>::iterator aIter = aConditions.begin();
159 ::std::vector<ExpressionNodeSharedPtr>::iterator aEnd = aConditions.end();
160 for (; aIter != aEnd; ++aIter)
162 if ( (*aIter)->evaluate(aRow)->getValue().getBool() )
164 ++aIter;
165 (*aIter)->fill(aRow);
167 else
168 ++aIter;
170 aTypeInfoRows.push_back(aRow);
172 m_aTypeInfoRows = aTypeInfoRows;
175 ::connectivity::ODatabaseMetaDataResultSet* pResult = new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eTypeInfo);
176 Reference< XResultSet > xRet = pResult;
177 pResult->setRows(m_aTypeInfoRows);
178 return xRet;
180 // -------------------------------------------------------------------------
181 Reference< XResultSet > SAL_CALL ODatabaseMetaDataBase::getExportedKeys(
182 const Any& /*catalog*/, const ::rtl::OUString& /*schema*/, const ::rtl::OUString& /*table*/ ) throw(SQLException, RuntimeException)
184 return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eExportedKeys );
186 // -------------------------------------------------------------------------
187 Reference< XResultSet > SAL_CALL ODatabaseMetaDataBase::getImportedKeys(
188 const Any& /*catalog*/, const ::rtl::OUString& /*schema*/, const ::rtl::OUString& /*table*/ ) throw(SQLException, RuntimeException)
190 return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eImportedKeys );
192 // -------------------------------------------------------------------------
193 Reference< XResultSet > SAL_CALL ODatabaseMetaDataBase::getPrimaryKeys(
194 const Any& /*catalog*/, const ::rtl::OUString& /*schema*/, const ::rtl::OUString& /*table*/ ) throw(SQLException, RuntimeException)
196 return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::ePrimaryKeys );
198 // -------------------------------------------------------------------------
199 Reference< XResultSet > SAL_CALL ODatabaseMetaDataBase::getIndexInfo(
200 const Any& /*catalog*/, const ::rtl::OUString& /*schema*/, const ::rtl::OUString& /*table*/,
201 sal_Bool /*unique*/, sal_Bool /*approximate*/ ) throw(SQLException, RuntimeException)
203 return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eIndexInfo );
205 // -------------------------------------------------------------------------
206 Reference< XResultSet > SAL_CALL ODatabaseMetaDataBase::getBestRowIdentifier(
207 const Any& /*catalog*/, const ::rtl::OUString& /*schema*/, const ::rtl::OUString& /*table*/, sal_Int32 /*scope*/,
208 sal_Bool /*nullable*/ ) throw(SQLException, RuntimeException)
210 return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eBestRowIdentifier );
212 // -------------------------------------------------------------------------
213 Reference< XResultSet > SAL_CALL ODatabaseMetaDataBase::getCrossReference(
214 const Any& /*primaryCatalog*/, const ::rtl::OUString& /*primarySchema*/,
215 const ::rtl::OUString& /*primaryTable*/, const Any& /*foreignCatalog*/,
216 const ::rtl::OUString& /*foreignSchema*/, const ::rtl::OUString& /*foreignTable*/ ) throw(SQLException, RuntimeException)
218 return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eCrossReference );
220 // -------------------------------------------------------------------------
221 Reference< XConnection > SAL_CALL ODatabaseMetaDataBase::getConnection( ) throw(SQLException, RuntimeException)
223 return m_xConnection;
225 // -------------------------------------------------------------------------
226 Reference< XResultSet > SAL_CALL ODatabaseMetaDataBase::getProcedureColumns(
227 const Any& /*catalog*/, const ::rtl::OUString& /*schemaPattern*/,
228 const ::rtl::OUString& /*procedureNamePattern*/, const ::rtl::OUString& /*columnNamePattern*/ ) throw(SQLException, RuntimeException)
230 return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eProcedureColumns );
232 // -------------------------------------------------------------------------
233 Reference< XResultSet > SAL_CALL ODatabaseMetaDataBase::getProcedures(
234 const Any& /*catalog*/, const ::rtl::OUString& /*schemaPattern*/,
235 const ::rtl::OUString& /*procedureNamePattern*/ ) throw(SQLException, RuntimeException)
237 return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eProcedures );
239 // -------------------------------------------------------------------------
240 Reference< XResultSet > SAL_CALL ODatabaseMetaDataBase::getVersionColumns(
241 const Any& /*catalog*/, const ::rtl::OUString& /*schema*/, const ::rtl::OUString& /*table*/ ) throw(SQLException, RuntimeException)
243 return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eVersionColumns );
245 // -------------------------------------------------------------------------
246 Reference< XResultSet > SAL_CALL ODatabaseMetaDataBase::getSchemas( ) throw(SQLException, RuntimeException)
248 return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eSchemas );
250 // -------------------------------------------------------------------------
251 Reference< XResultSet > SAL_CALL ODatabaseMetaDataBase::getColumnPrivileges(
252 const Any& /*catalog*/, const ::rtl::OUString& /*schema*/, const ::rtl::OUString& /*table*/,
253 const ::rtl::OUString& /*columnNamePattern*/ ) throw(SQLException, RuntimeException)
255 return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eColumnPrivileges );
257 // -------------------------------------------------------------------------
258 Reference< XResultSet > SAL_CALL ODatabaseMetaDataBase::getTablePrivileges(
259 const Any& /*catalog*/, const ::rtl::OUString& /*schema*/, const ::rtl::OUString& /*table*/) throw(SQLException, RuntimeException)
261 return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eTablePrivileges );
263 // -------------------------------------------------------------------------
264 Reference< XResultSet > SAL_CALL ODatabaseMetaDataBase::getCatalogs( ) throw(SQLException, RuntimeException)
266 return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eCatalogs );
268 // -----------------------------------------------------------------------------
269 ::rtl::OUString SAL_CALL ODatabaseMetaDataBase::getIdentifierQuoteString( ) throw(SQLException, RuntimeException)
271 return callImplMethod(m_sIdentifierQuoteString,::std::mem_fun_t< ::rtl::OUString ,ODatabaseMetaDataBase>(&ODatabaseMetaDataBase::impl_getIdentifierQuoteString_throw));
273 // -----------------------------------------------------------------------------
274 sal_Bool SAL_CALL ODatabaseMetaDataBase::isCatalogAtStart( ) throw(SQLException, RuntimeException)
276 return callImplMethod(m_isCatalogAtStart,::std::mem_fun_t< sal_Bool,ODatabaseMetaDataBase>(&ODatabaseMetaDataBase::impl_isCatalogAtStart_throw));
278 // -----------------------------------------------------------------------------
279 ::rtl::OUString SAL_CALL ODatabaseMetaDataBase::getCatalogSeparator( ) throw(SQLException, RuntimeException)
281 return callImplMethod(m_sCatalogSeparator,::std::mem_fun_t< ::rtl::OUString,ODatabaseMetaDataBase>(&ODatabaseMetaDataBase::impl_getCatalogSeparator_throw));
283 // -----------------------------------------------------------------------------
284 sal_Bool SAL_CALL ODatabaseMetaDataBase::supportsCatalogsInTableDefinitions( ) throw(SQLException, RuntimeException)
286 return callImplMethod(m_supportsCatalogsInTableDefinitions,::std::mem_fun_t< sal_Bool,ODatabaseMetaDataBase>(&ODatabaseMetaDataBase::impl_supportsCatalogsInTableDefinitions_throw));
288 // -----------------------------------------------------------------------------
289 sal_Bool SAL_CALL ODatabaseMetaDataBase::supportsSchemasInTableDefinitions( ) throw(SQLException, RuntimeException)
291 return callImplMethod(m_supportsSchemasInTableDefinitions,::std::mem_fun_t< sal_Bool,ODatabaseMetaDataBase>(&ODatabaseMetaDataBase::impl_supportsSchemasInTableDefinitions_throw));
293 // -----------------------------------------------------------------------------
294 sal_Bool SAL_CALL ODatabaseMetaDataBase::supportsCatalogsInDataManipulation( ) throw(SQLException, RuntimeException)
296 return callImplMethod(m_supportsCatalogsInDataManipulation,::std::mem_fun_t< sal_Bool,ODatabaseMetaDataBase>(&ODatabaseMetaDataBase::impl_supportsCatalogsInDataManipulation_throw));
298 // -----------------------------------------------------------------------------
299 sal_Bool SAL_CALL ODatabaseMetaDataBase::supportsSchemasInDataManipulation( ) throw(SQLException, RuntimeException)
301 return callImplMethod(m_supportsSchemasInDataManipulation,::std::mem_fun_t< sal_Bool,ODatabaseMetaDataBase>(&ODatabaseMetaDataBase::impl_supportsSchemasInDataManipulation_throw));
303 // -----------------------------------------------------------------------------
304 sal_Bool SAL_CALL ODatabaseMetaDataBase::supportsMixedCaseQuotedIdentifiers( ) throw(SQLException, RuntimeException)
306 return callImplMethod(m_supportsMixedCaseQuotedIdentifiers,::std::mem_fun_t< sal_Bool,ODatabaseMetaDataBase>(&ODatabaseMetaDataBase::impl_supportsMixedCaseQuotedIdentifiers_throw));
308 // -----------------------------------------------------------------------------
309 sal_Bool SAL_CALL ODatabaseMetaDataBase::supportsAlterTableWithAddColumn( ) throw(SQLException, RuntimeException)
311 return callImplMethod(m_supportsAlterTableWithAddColumn,::std::mem_fun_t< sal_Bool,ODatabaseMetaDataBase>(&ODatabaseMetaDataBase::impl_supportsAlterTableWithAddColumn_throw));
313 // -----------------------------------------------------------------------------
314 sal_Bool SAL_CALL ODatabaseMetaDataBase::supportsAlterTableWithDropColumn( ) throw(SQLException, RuntimeException)
316 return callImplMethod(m_supportsAlterTableWithDropColumn,::std::mem_fun_t< sal_Bool,ODatabaseMetaDataBase>(&ODatabaseMetaDataBase::impl_supportsAlterTableWithDropColumn_throw));
318 // -----------------------------------------------------------------------------
319 sal_Int32 SAL_CALL ODatabaseMetaDataBase::getMaxStatements( ) throw(SQLException, RuntimeException)
321 return callImplMethod(m_MaxStatements,::std::mem_fun_t< sal_Int32,ODatabaseMetaDataBase>(&ODatabaseMetaDataBase::impl_getMaxStatements_throw));
323 // -----------------------------------------------------------------------------
324 sal_Int32 SAL_CALL ODatabaseMetaDataBase::getMaxTablesInSelect( ) throw(SQLException, RuntimeException)
326 return callImplMethod(m_MaxTablesInSelect,::std::mem_fun_t< sal_Int32,ODatabaseMetaDataBase>(&ODatabaseMetaDataBase::impl_getMaxTablesInSelect_throw));
328 // -----------------------------------------------------------------------------
329 sal_Bool SAL_CALL ODatabaseMetaDataBase::storesMixedCaseQuotedIdentifiers( ) throw(SQLException, RuntimeException)
331 return callImplMethod(m_storesMixedCaseQuotedIdentifiers,::std::mem_fun_t< sal_Bool,ODatabaseMetaDataBase>(&ODatabaseMetaDataBase::impl_storesMixedCaseQuotedIdentifiers_throw));
333 // -----------------------------------------------------------------------------
335 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */