1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
);
61 xCom
->addEventListener(m_xListenerHelper
);
63 osl_atomic_decrement( &m_refCount
);
66 ODatabaseMetaDataBase::~ODatabaseMetaDataBase()
71 Sequence
< PropertyValue
> SAL_CALL
ODatabaseMetaDataBase::getConnectionInfo( ) throw (RuntimeException
, std::exception
)
73 return m_aConnectionInfo
;
77 void SAL_CALL
ODatabaseMetaDataBase::disposing( const EventObject
& /*Source*/ ) throw(RuntimeException
, std::exception
)
79 // cut off all references to the connection
80 m_xConnection
.clear();
81 m_xListenerHelper
.clear();
84 Reference
< XResultSet
> SAL_CALL
ODatabaseMetaDataBase::getTypeInfo( ) throw(SQLException
, RuntimeException
, std::exception
)
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("TypeInfoSettings",aTypeInfoSettings
);
97 static const sal_Int32 pTypes
[] = {
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
)));
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 const sal_Int32
* pType
= pTypes
;
141 for (sal_Int32 i
= 1; i
<= sal_Int32(sizeof(pTypes
)/sizeof(pTypes
[0])); ++i
,++pType
)
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() )
155 (*aIter
)->fill(aRow
);
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
);
171 Reference
< XResultSet
> SAL_CALL
ODatabaseMetaDataBase::getExportedKeys(
172 const Any
& /*catalog*/, const OUString
& /*schema*/, const OUString
& /*table*/ ) throw(SQLException
, RuntimeException
, std::exception
)
174 return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eExportedKeys
);
177 Reference
< XResultSet
> SAL_CALL
ODatabaseMetaDataBase::getImportedKeys(
178 const Any
& /*catalog*/, const OUString
& /*schema*/, const OUString
& /*table*/ ) throw(SQLException
, RuntimeException
, std::exception
)
180 return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eImportedKeys
);
183 Reference
< XResultSet
> SAL_CALL
ODatabaseMetaDataBase::getPrimaryKeys(
184 const Any
& /*catalog*/, const OUString
& /*schema*/, const OUString
& /*table*/ ) throw(SQLException
, RuntimeException
, std::exception
)
186 return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::ePrimaryKeys
);
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
, std::exception
)
193 return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eIndexInfo
);
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
, std::exception
)
200 return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eBestRowIdentifier
);
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
, std::exception
)
208 return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eCrossReference
);
211 Reference
< XConnection
> SAL_CALL
ODatabaseMetaDataBase::getConnection( ) throw(SQLException
, RuntimeException
, std::exception
)
213 return m_xConnection
;
216 Reference
< XResultSet
> SAL_CALL
ODatabaseMetaDataBase::getProcedureColumns(
217 const Any
& /*catalog*/, const OUString
& /*schemaPattern*/,
218 const OUString
& /*procedureNamePattern*/, const OUString
& /*columnNamePattern*/ ) throw(SQLException
, RuntimeException
, std::exception
)
220 return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eProcedureColumns
);
223 Reference
< XResultSet
> SAL_CALL
ODatabaseMetaDataBase::getProcedures(
224 const Any
& /*catalog*/, const OUString
& /*schemaPattern*/,
225 const OUString
& /*procedureNamePattern*/ ) throw(SQLException
, RuntimeException
, std::exception
)
227 return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eProcedures
);
230 Reference
< XResultSet
> SAL_CALL
ODatabaseMetaDataBase::getVersionColumns(
231 const Any
& /*catalog*/, const OUString
& /*schema*/, const OUString
& /*table*/ ) throw(SQLException
, RuntimeException
, std::exception
)
233 return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eVersionColumns
);
236 Reference
< XResultSet
> SAL_CALL
ODatabaseMetaDataBase::getSchemas( ) throw(SQLException
, RuntimeException
, std::exception
)
238 return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eSchemas
);
241 Reference
< XResultSet
> SAL_CALL
ODatabaseMetaDataBase::getColumnPrivileges(
242 const Any
& /*catalog*/, const OUString
& /*schema*/, const OUString
& /*table*/,
243 const OUString
& /*columnNamePattern*/ ) throw(SQLException
, RuntimeException
, std::exception
)
245 return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eColumnPrivileges
);
248 Reference
< XResultSet
> SAL_CALL
ODatabaseMetaDataBase::getTablePrivileges(
249 const Any
& /*catalog*/, const OUString
& /*schema*/, const OUString
& /*table*/) throw(SQLException
, RuntimeException
, std::exception
)
251 return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eTablePrivileges
);
254 Reference
< XResultSet
> SAL_CALL
ODatabaseMetaDataBase::getCatalogs( ) throw(SQLException
, RuntimeException
, std::exception
)
256 return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eCatalogs
);
259 OUString SAL_CALL
ODatabaseMetaDataBase::getIdentifierQuoteString( ) throw(SQLException
, RuntimeException
, std::exception
)
261 return callImplMethod(m_sIdentifierQuoteString
,::std::mem_fun_t
< OUString
,ODatabaseMetaDataBase
>(&ODatabaseMetaDataBase::impl_getIdentifierQuoteString_throw
));
264 sal_Bool SAL_CALL
ODatabaseMetaDataBase::isCatalogAtStart( ) throw(SQLException
, RuntimeException
, std::exception
)
266 return callImplMethod(m_isCatalogAtStart
,::std::mem_fun_t
< bool,ODatabaseMetaDataBase
>(&ODatabaseMetaDataBase::impl_isCatalogAtStart_throw
));
269 OUString SAL_CALL
ODatabaseMetaDataBase::getCatalogSeparator( ) throw(SQLException
, RuntimeException
, std::exception
)
271 return callImplMethod(m_sCatalogSeparator
,::std::mem_fun_t
< OUString
,ODatabaseMetaDataBase
>(&ODatabaseMetaDataBase::impl_getCatalogSeparator_throw
));
274 sal_Bool SAL_CALL
ODatabaseMetaDataBase::supportsCatalogsInTableDefinitions( ) throw(SQLException
, RuntimeException
, std::exception
)
276 return callImplMethod(m_supportsCatalogsInTableDefinitions
,::std::mem_fun_t
< bool,ODatabaseMetaDataBase
>(&ODatabaseMetaDataBase::impl_supportsCatalogsInTableDefinitions_throw
));
279 sal_Bool SAL_CALL
ODatabaseMetaDataBase::supportsSchemasInTableDefinitions( ) throw(SQLException
, RuntimeException
, std::exception
)
281 return callImplMethod(m_supportsSchemasInTableDefinitions
,::std::mem_fun_t
< bool,ODatabaseMetaDataBase
>(&ODatabaseMetaDataBase::impl_supportsSchemasInTableDefinitions_throw
));
284 sal_Bool SAL_CALL
ODatabaseMetaDataBase::supportsCatalogsInDataManipulation( ) throw(SQLException
, RuntimeException
, std::exception
)
286 return callImplMethod(m_supportsCatalogsInDataManipulation
,::std::mem_fun_t
< bool,ODatabaseMetaDataBase
>(&ODatabaseMetaDataBase::impl_supportsCatalogsInDataManipulation_throw
));
289 sal_Bool SAL_CALL
ODatabaseMetaDataBase::supportsSchemasInDataManipulation( ) throw(SQLException
, RuntimeException
, std::exception
)
291 return callImplMethod(m_supportsSchemasInDataManipulation
,::std::mem_fun_t
< bool,ODatabaseMetaDataBase
>(&ODatabaseMetaDataBase::impl_supportsSchemasInDataManipulation_throw
));
294 sal_Bool SAL_CALL
ODatabaseMetaDataBase::supportsMixedCaseQuotedIdentifiers( ) throw(SQLException
, RuntimeException
, std::exception
)
296 return callImplMethod(m_supportsMixedCaseQuotedIdentifiers
,::std::mem_fun_t
< bool,ODatabaseMetaDataBase
>(&ODatabaseMetaDataBase::impl_supportsMixedCaseQuotedIdentifiers_throw
));
299 sal_Bool SAL_CALL
ODatabaseMetaDataBase::supportsAlterTableWithAddColumn( ) throw(SQLException
, RuntimeException
, std::exception
)
301 return callImplMethod(m_supportsAlterTableWithAddColumn
,::std::mem_fun_t
< bool,ODatabaseMetaDataBase
>(&ODatabaseMetaDataBase::impl_supportsAlterTableWithAddColumn_throw
));
304 sal_Bool SAL_CALL
ODatabaseMetaDataBase::supportsAlterTableWithDropColumn( ) throw(SQLException
, RuntimeException
, std::exception
)
306 return callImplMethod(m_supportsAlterTableWithDropColumn
,::std::mem_fun_t
< bool,ODatabaseMetaDataBase
>(&ODatabaseMetaDataBase::impl_supportsAlterTableWithDropColumn_throw
));
309 sal_Int32 SAL_CALL
ODatabaseMetaDataBase::getMaxStatements( ) throw(SQLException
, RuntimeException
, std::exception
)
311 return callImplMethod(m_MaxStatements
,::std::mem_fun_t
< sal_Int32
,ODatabaseMetaDataBase
>(&ODatabaseMetaDataBase::impl_getMaxStatements_throw
));
314 sal_Int32 SAL_CALL
ODatabaseMetaDataBase::getMaxTablesInSelect( ) throw(SQLException
, RuntimeException
, std::exception
)
316 return callImplMethod(m_MaxTablesInSelect
,::std::mem_fun_t
< sal_Int32
,ODatabaseMetaDataBase
>(&ODatabaseMetaDataBase::impl_getMaxTablesInSelect_throw
));
319 sal_Bool SAL_CALL
ODatabaseMetaDataBase::storesMixedCaseQuotedIdentifiers( ) throw(SQLException
, RuntimeException
, std::exception
)
321 return callImplMethod(m_storesMixedCaseQuotedIdentifiers
,::std::mem_fun_t
< bool,ODatabaseMetaDataBase
>(&ODatabaseMetaDataBase::impl_storesMixedCaseQuotedIdentifiers_throw
));
325 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */