1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: TDatabaseMetaDataBase.cxx,v $
10 * $Revision: 1.8.56.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_connectivity.hxx"
33 #include "TDatabaseMetaDataBase.hxx"
34 #include "RowFunctionParser.hxx"
36 #include <comphelper/sequenceashashmap.hxx>
37 #include <comphelper/evtlistenerhlp.hxx>
38 #include <com/sun/star/lang/XComponent.hpp>
39 #include "resource/sharedresources.hxx"
40 #include "resource/common_res.hrc"
41 #include <connectivity/dbexception.hxx>
43 using namespace com::sun::star::uno
;
44 using namespace com::sun::star::lang
;
45 using namespace com::sun::star::sdbc
;
46 using namespace com::sun::star::lang
;
47 using namespace com::sun::star::beans
;
48 using namespace comphelper
;
49 using namespace connectivity
;
52 ODatabaseMetaDataBase::ODatabaseMetaDataBase(const Reference
< XConnection
>& _rxConnection
,const Sequence
< PropertyValue
>& _rInfo
)
53 : m_aConnectionInfo(_rInfo
)
54 ,m_isCatalogAtStart(false,sal_False
)
55 ,m_sCatalogSeparator(false,::rtl::OUString())
56 ,m_sIdentifierQuoteString(false,::rtl::OUString())
57 ,m_supportsCatalogsInTableDefinitions(false,sal_False
)
58 ,m_supportsSchemasInTableDefinitions(false,sal_False
)
59 ,m_supportsCatalogsInDataManipulation(false,sal_False
)
60 ,m_supportsSchemasInDataManipulation(false,sal_False
)
61 ,m_supportsMixedCaseQuotedIdentifiers(false,sal_False
)
62 ,m_supportsAlterTableWithAddColumn(false,sal_False
)
63 ,m_supportsAlterTableWithDropColumn(false,sal_False
)
64 ,m_MaxStatements(false,0)
65 ,m_MaxTablesInSelect(false,0)
66 ,m_storesMixedCaseQuotedIdentifiers(false,sal_False
)
67 , m_xConnection(_rxConnection
)
69 osl_incrementInterlockedCount( &m_refCount
);
71 m_xListenerHelper
= new OEventListenerHelper(this);
72 Reference
<XComponent
> xCom(m_xConnection
,UNO_QUERY
);
74 xCom
->addEventListener(m_xListenerHelper
);
76 osl_decrementInterlockedCount( &m_refCount
);
78 // -------------------------------------------------------------------------
79 ODatabaseMetaDataBase::~ODatabaseMetaDataBase()
83 // -----------------------------------------------------------------------------
84 Sequence
< PropertyValue
> SAL_CALL
ODatabaseMetaDataBase::getConnectionInfo( ) throw (RuntimeException
)
86 return m_aConnectionInfo
;
89 // -----------------------------------------------------------------------------
90 void SAL_CALL
ODatabaseMetaDataBase::disposing( const EventObject
& /*Source*/ ) throw(RuntimeException
)
92 // cut off all references to the connection
93 m_xConnection
.clear();
94 m_xListenerHelper
.clear();
96 // -----------------------------------------------------------------------------
97 Reference
< XResultSet
> SAL_CALL
ODatabaseMetaDataBase::getTypeInfo( ) throw(SQLException
, RuntimeException
)
99 ::osl::MutexGuard
aGuard( m_aMutex
);
100 if ( m_aTypeInfoRows
.empty() )
102 Reference
< XResultSet
> xRet
= impl_getTypeInfo_throw();
103 Reference
< XRow
> xRow(xRet
,UNO_QUERY
);
104 ::comphelper::SequenceAsHashMap
aMap(m_aConnectionInfo
);
105 Sequence
< Any
> aTypeInfoSettings
;
106 aTypeInfoSettings
= aMap
.getUnpackedValueOrDefault(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TypeInfoSettings")),aTypeInfoSettings
);
110 static sal_Int32 pTypes
[] = {
130 ::std::vector
<ExpressionNodeSharedPtr
> aConditions
;
131 if ( aTypeInfoSettings
.getLength() > 1 && ((aTypeInfoSettings
.getLength() % 2) == 0) )
133 const Any
* pIter
= aTypeInfoSettings
.getConstArray();
134 const Any
* pEnd
= pIter
+ aTypeInfoSettings
.getLength();
137 for(;pIter
!= pEnd
;++pIter
)
138 aConditions
.push_back(FunctionParser::parseFunction(::comphelper::getString(*pIter
)));
142 ::connectivity::SharedResources aResources
;
143 const ::rtl::OUString
sError( aResources
.getResourceString(STR_FORMULA_WRONG
));
144 ::dbtools::throwGenericSQLException(sError
,*this);
148 while( xRet
->next() )
150 ::connectivity::ODatabaseMetaDataResultSet::ORow aRow
;
151 aRow
.push_back(ODatabaseMetaDataResultSet::getEmptyValue());
152 sal_Int32
* pType
= pTypes
;
153 for (sal_Int32 i
= 1; i
<= sal_Int32(sizeof(pTypes
)/sizeof(pTypes
[0])); ++i
,++pType
)
156 aValue
.fill(i
,*pType
,xRow
);
157 aRow
.push_back(new ORowSetValueDecorator(aValue
));
160 ::std::vector
<ExpressionNodeSharedPtr
>::iterator aIter
= aConditions
.begin();
161 ::std::vector
<ExpressionNodeSharedPtr
>::iterator aEnd
= aConditions
.end();
162 for (; aIter
!= aEnd
; ++aIter
)
164 if ( (*aIter
)->evaluate(aRow
)->getValue().getBool() )
167 (*aIter
)->fill(aRow
);
172 m_aTypeInfoRows
.push_back(aRow
);
176 ::connectivity::ODatabaseMetaDataResultSet
* pResult
= new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eTypeInfo
);
177 Reference
< XResultSet
> xRet
= pResult
;
178 pResult
->setRows(m_aTypeInfoRows
);
181 // -------------------------------------------------------------------------
182 Reference
< XResultSet
> SAL_CALL
ODatabaseMetaDataBase::getExportedKeys(
183 const Any
& /*catalog*/, const ::rtl::OUString
& /*schema*/, const ::rtl::OUString
& /*table*/ ) throw(SQLException
, RuntimeException
)
185 return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eExportedKeys
);
187 // -------------------------------------------------------------------------
188 Reference
< XResultSet
> SAL_CALL
ODatabaseMetaDataBase::getImportedKeys(
189 const Any
& /*catalog*/, const ::rtl::OUString
& /*schema*/, const ::rtl::OUString
& /*table*/ ) throw(SQLException
, RuntimeException
)
191 return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eImportedKeys
);
193 // -------------------------------------------------------------------------
194 Reference
< XResultSet
> SAL_CALL
ODatabaseMetaDataBase::getPrimaryKeys(
195 const Any
& /*catalog*/, const ::rtl::OUString
& /*schema*/, const ::rtl::OUString
& /*table*/ ) throw(SQLException
, RuntimeException
)
197 return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::ePrimaryKeys
);
199 // -------------------------------------------------------------------------
200 Reference
< XResultSet
> SAL_CALL
ODatabaseMetaDataBase::getIndexInfo(
201 const Any
& /*catalog*/, const ::rtl::OUString
& /*schema*/, const ::rtl::OUString
& /*table*/,
202 sal_Bool
/*unique*/, sal_Bool
/*approximate*/ ) throw(SQLException
, RuntimeException
)
204 return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eIndexInfo
);
206 // -------------------------------------------------------------------------
207 Reference
< XResultSet
> SAL_CALL
ODatabaseMetaDataBase::getBestRowIdentifier(
208 const Any
& /*catalog*/, const ::rtl::OUString
& /*schema*/, const ::rtl::OUString
& /*table*/, sal_Int32
/*scope*/,
209 sal_Bool
/*nullable*/ ) throw(SQLException
, RuntimeException
)
211 return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eBestRowIdentifier
);
213 // -------------------------------------------------------------------------
214 Reference
< XResultSet
> SAL_CALL
ODatabaseMetaDataBase::getCrossReference(
215 const Any
& /*primaryCatalog*/, const ::rtl::OUString
& /*primarySchema*/,
216 const ::rtl::OUString
& /*primaryTable*/, const Any
& /*foreignCatalog*/,
217 const ::rtl::OUString
& /*foreignSchema*/, const ::rtl::OUString
& /*foreignTable*/ ) throw(SQLException
, RuntimeException
)
219 return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eCrossReference
);
221 // -------------------------------------------------------------------------
222 Reference
< XConnection
> SAL_CALL
ODatabaseMetaDataBase::getConnection( ) throw(SQLException
, RuntimeException
)
224 return m_xConnection
;
226 // -------------------------------------------------------------------------
227 Reference
< XResultSet
> SAL_CALL
ODatabaseMetaDataBase::getProcedureColumns(
228 const Any
& /*catalog*/, const ::rtl::OUString
& /*schemaPattern*/,
229 const ::rtl::OUString
& /*procedureNamePattern*/, const ::rtl::OUString
& /*columnNamePattern*/ ) throw(SQLException
, RuntimeException
)
231 return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eProcedureColumns
);
233 // -------------------------------------------------------------------------
234 Reference
< XResultSet
> SAL_CALL
ODatabaseMetaDataBase::getProcedures(
235 const Any
& /*catalog*/, const ::rtl::OUString
& /*schemaPattern*/,
236 const ::rtl::OUString
& /*procedureNamePattern*/ ) throw(SQLException
, RuntimeException
)
238 return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eProcedures
);
240 // -------------------------------------------------------------------------
241 Reference
< XResultSet
> SAL_CALL
ODatabaseMetaDataBase::getVersionColumns(
242 const Any
& /*catalog*/, const ::rtl::OUString
& /*schema*/, const ::rtl::OUString
& /*table*/ ) throw(SQLException
, RuntimeException
)
244 return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eVersionColumns
);
246 // -------------------------------------------------------------------------
247 Reference
< XResultSet
> SAL_CALL
ODatabaseMetaDataBase::getSchemas( ) throw(SQLException
, RuntimeException
)
249 return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eSchemas
);
251 // -------------------------------------------------------------------------
252 Reference
< XResultSet
> SAL_CALL
ODatabaseMetaDataBase::getColumnPrivileges(
253 const Any
& /*catalog*/, const ::rtl::OUString
& /*schema*/, const ::rtl::OUString
& /*table*/,
254 const ::rtl::OUString
& /*columnNamePattern*/ ) throw(SQLException
, RuntimeException
)
256 return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eColumnPrivileges
);
258 // -------------------------------------------------------------------------
259 Reference
< XResultSet
> SAL_CALL
ODatabaseMetaDataBase::getTablePrivileges(
260 const Any
& /*catalog*/, const ::rtl::OUString
& /*schema*/, const ::rtl::OUString
& /*table*/) throw(SQLException
, RuntimeException
)
262 return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eTablePrivileges
);
264 // -------------------------------------------------------------------------
265 Reference
< XResultSet
> SAL_CALL
ODatabaseMetaDataBase::getCatalogs( ) throw(SQLException
, RuntimeException
)
267 return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eCatalogs
);
269 // -----------------------------------------------------------------------------
270 ::rtl::OUString SAL_CALL
ODatabaseMetaDataBase::getIdentifierQuoteString( ) throw(SQLException
, RuntimeException
)
272 return callImplMethod(m_sIdentifierQuoteString
,::std::mem_fun_t
< ::rtl::OUString
,ODatabaseMetaDataBase
>(&ODatabaseMetaDataBase::impl_getIdentifierQuoteString_throw
));
274 // -----------------------------------------------------------------------------
275 sal_Bool SAL_CALL
ODatabaseMetaDataBase::isCatalogAtStart( ) throw(SQLException
, RuntimeException
)
277 return callImplMethod(m_isCatalogAtStart
,::std::mem_fun_t
< sal_Bool
,ODatabaseMetaDataBase
>(&ODatabaseMetaDataBase::impl_isCatalogAtStart_throw
));
279 // -----------------------------------------------------------------------------
280 ::rtl::OUString SAL_CALL
ODatabaseMetaDataBase::getCatalogSeparator( ) throw(SQLException
, RuntimeException
)
282 return callImplMethod(m_sCatalogSeparator
,::std::mem_fun_t
< ::rtl::OUString
,ODatabaseMetaDataBase
>(&ODatabaseMetaDataBase::impl_getCatalogSeparator_throw
));
284 // -----------------------------------------------------------------------------
285 sal_Bool SAL_CALL
ODatabaseMetaDataBase::supportsCatalogsInTableDefinitions( ) throw(SQLException
, RuntimeException
)
287 return callImplMethod(m_supportsCatalogsInTableDefinitions
,::std::mem_fun_t
< sal_Bool
,ODatabaseMetaDataBase
>(&ODatabaseMetaDataBase::impl_supportsCatalogsInTableDefinitions_throw
));
289 // -----------------------------------------------------------------------------
290 sal_Bool SAL_CALL
ODatabaseMetaDataBase::supportsSchemasInTableDefinitions( ) throw(SQLException
, RuntimeException
)
292 return callImplMethod(m_supportsSchemasInTableDefinitions
,::std::mem_fun_t
< sal_Bool
,ODatabaseMetaDataBase
>(&ODatabaseMetaDataBase::impl_supportsSchemasInTableDefinitions_throw
));
294 // -----------------------------------------------------------------------------
295 sal_Bool SAL_CALL
ODatabaseMetaDataBase::supportsCatalogsInDataManipulation( ) throw(SQLException
, RuntimeException
)
297 return callImplMethod(m_supportsCatalogsInDataManipulation
,::std::mem_fun_t
< sal_Bool
,ODatabaseMetaDataBase
>(&ODatabaseMetaDataBase::impl_supportsCatalogsInDataManipulation_throw
));
299 // -----------------------------------------------------------------------------
300 sal_Bool SAL_CALL
ODatabaseMetaDataBase::supportsSchemasInDataManipulation( ) throw(SQLException
, RuntimeException
)
302 return callImplMethod(m_supportsSchemasInDataManipulation
,::std::mem_fun_t
< sal_Bool
,ODatabaseMetaDataBase
>(&ODatabaseMetaDataBase::impl_supportsSchemasInDataManipulation_throw
));
304 // -----------------------------------------------------------------------------
305 sal_Bool SAL_CALL
ODatabaseMetaDataBase::supportsMixedCaseQuotedIdentifiers( ) throw(SQLException
, RuntimeException
)
307 return callImplMethod(m_supportsMixedCaseQuotedIdentifiers
,::std::mem_fun_t
< sal_Bool
,ODatabaseMetaDataBase
>(&ODatabaseMetaDataBase::impl_supportsMixedCaseQuotedIdentifiers_throw
));
309 // -----------------------------------------------------------------------------
310 sal_Bool SAL_CALL
ODatabaseMetaDataBase::supportsAlterTableWithAddColumn( ) throw(SQLException
, RuntimeException
)
312 return callImplMethod(m_supportsAlterTableWithAddColumn
,::std::mem_fun_t
< sal_Bool
,ODatabaseMetaDataBase
>(&ODatabaseMetaDataBase::impl_supportsAlterTableWithAddColumn_throw
));
314 // -----------------------------------------------------------------------------
315 sal_Bool SAL_CALL
ODatabaseMetaDataBase::supportsAlterTableWithDropColumn( ) throw(SQLException
, RuntimeException
)
317 return callImplMethod(m_supportsAlterTableWithDropColumn
,::std::mem_fun_t
< sal_Bool
,ODatabaseMetaDataBase
>(&ODatabaseMetaDataBase::impl_supportsAlterTableWithDropColumn_throw
));
319 // -----------------------------------------------------------------------------
320 sal_Int32 SAL_CALL
ODatabaseMetaDataBase::getMaxStatements( ) throw(SQLException
, RuntimeException
)
322 return callImplMethod(m_MaxStatements
,::std::mem_fun_t
< sal_Int32
,ODatabaseMetaDataBase
>(&ODatabaseMetaDataBase::impl_getMaxStatements_throw
));
324 // -----------------------------------------------------------------------------
325 sal_Int32 SAL_CALL
ODatabaseMetaDataBase::getMaxTablesInSelect( ) throw(SQLException
, RuntimeException
)
327 return callImplMethod(m_MaxTablesInSelect
,::std::mem_fun_t
< sal_Int32
,ODatabaseMetaDataBase
>(&ODatabaseMetaDataBase::impl_getMaxTablesInSelect_throw
));
329 // -----------------------------------------------------------------------------
330 sal_Bool SAL_CALL
ODatabaseMetaDataBase::storesMixedCaseQuotedIdentifiers( ) throw(SQLException
, RuntimeException
)
332 return callImplMethod(m_storesMixedCaseQuotedIdentifiers
,::std::mem_fun_t
< sal_Bool
,ODatabaseMetaDataBase
>(&ODatabaseMetaDataBase::impl_storesMixedCaseQuotedIdentifiers_throw
));
334 // -----------------------------------------------------------------------------