1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_connectivity.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include "connectivity/dbmetadata.hxx"
32*cdf0e10cSrcweir #include "connectivity/dbexception.hxx"
33*cdf0e10cSrcweir #include "connectivity/DriversConfig.hxx"
34*cdf0e10cSrcweir #include "resource/common_res.hrc"
35*cdf0e10cSrcweir #include "resource/sharedresources.hxx"
36*cdf0e10cSrcweir 
37*cdf0e10cSrcweir /** === begin UNO includes === **/
38*cdf0e10cSrcweir #include <com/sun/star/lang/IllegalArgumentException.hpp>
39*cdf0e10cSrcweir #include <com/sun/star/container/XChild.hpp>
40*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
41*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp>
42*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySetInfo.hpp>
43*cdf0e10cSrcweir #include <com/sun/star/sdb/BooleanComparisonMode.hpp>
44*cdf0e10cSrcweir #include <com/sun/star/sdbc/XDatabaseMetaData2.hpp>
45*cdf0e10cSrcweir #include <com/sun/star/sdbcx/XUsersSupplier.hpp>
46*cdf0e10cSrcweir #include <com/sun/star/sdbcx/XDataDefinitionSupplier.hpp>
47*cdf0e10cSrcweir #include <com/sun/star/sdbc/XDriverAccess.hpp>
48*cdf0e10cSrcweir /** === end UNO includes === **/
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir #include <tools/diagnose_ex.h>
51*cdf0e10cSrcweir #include <comphelper/namedvaluecollection.hxx>
52*cdf0e10cSrcweir #include <comphelper/componentcontext.hxx>
53*cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir #include <boost/optional.hpp>
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir //........................................................................
58*cdf0e10cSrcweir namespace dbtools
59*cdf0e10cSrcweir {
60*cdf0e10cSrcweir //........................................................................
61*cdf0e10cSrcweir 
62*cdf0e10cSrcweir     /** === begin UNO using === **/
63*cdf0e10cSrcweir     using ::com::sun::star::uno::Reference;
64*cdf0e10cSrcweir     using ::com::sun::star::sdbc::XConnection;
65*cdf0e10cSrcweir     using ::com::sun::star::sdbc::XConnection;
66*cdf0e10cSrcweir     using ::com::sun::star::sdbc::XDatabaseMetaData;
67*cdf0e10cSrcweir     using ::com::sun::star::sdbc::XDatabaseMetaData2;
68*cdf0e10cSrcweir     using ::com::sun::star::lang::IllegalArgumentException;
69*cdf0e10cSrcweir     using ::com::sun::star::uno::Exception;
70*cdf0e10cSrcweir     using ::com::sun::star::uno::Any;
71*cdf0e10cSrcweir     using ::com::sun::star::container::XChild;
72*cdf0e10cSrcweir     using ::com::sun::star::uno::UNO_QUERY_THROW;
73*cdf0e10cSrcweir     using ::com::sun::star::beans::XPropertySet;
74*cdf0e10cSrcweir     using ::com::sun::star::uno::Sequence;
75*cdf0e10cSrcweir     using ::com::sun::star::beans::PropertyValue;
76*cdf0e10cSrcweir     using ::com::sun::star::beans::XPropertySetInfo;
77*cdf0e10cSrcweir     using ::com::sun::star::uno::UNO_QUERY;
78*cdf0e10cSrcweir     using ::com::sun::star::sdbcx::XUsersSupplier;
79*cdf0e10cSrcweir     using ::com::sun::star::sdbcx::XDataDefinitionSupplier;
80*cdf0e10cSrcweir     using ::com::sun::star::sdbc::XDriverAccess;
81*cdf0e10cSrcweir     using ::com::sun::star::uno::UNO_SET_THROW;
82*cdf0e10cSrcweir     /** === end UNO using === **/
83*cdf0e10cSrcweir     namespace BooleanComparisonMode = ::com::sun::star::sdb::BooleanComparisonMode;
84*cdf0e10cSrcweir 
85*cdf0e10cSrcweir     //====================================================================
86*cdf0e10cSrcweir 	//= DatabaseMetaData_Impl
87*cdf0e10cSrcweir 	//====================================================================
88*cdf0e10cSrcweir     struct DatabaseMetaData_Impl
89*cdf0e10cSrcweir     {
90*cdf0e10cSrcweir         Reference< XConnection >        xConnection;
91*cdf0e10cSrcweir         Reference< XDatabaseMetaData >  xConnectionMetaData;
92*cdf0e10cSrcweir         ::connectivity::DriversConfig   aDriverConfig;
93*cdf0e10cSrcweir 
94*cdf0e10cSrcweir         ::boost::optional< ::rtl::OUString >    sCachedIdentifierQuoteString;
95*cdf0e10cSrcweir         ::boost::optional< ::rtl::OUString >    sCachedCatalogSeparator;
96*cdf0e10cSrcweir 
97*cdf0e10cSrcweir         DatabaseMetaData_Impl()
98*cdf0e10cSrcweir             :xConnection()
99*cdf0e10cSrcweir             ,xConnectionMetaData()
100*cdf0e10cSrcweir             ,aDriverConfig( ::comphelper::getProcessServiceFactory() )
101*cdf0e10cSrcweir             ,sCachedIdentifierQuoteString()
102*cdf0e10cSrcweir             ,sCachedCatalogSeparator()
103*cdf0e10cSrcweir         {
104*cdf0e10cSrcweir         }
105*cdf0e10cSrcweir     };
106*cdf0e10cSrcweir 
107*cdf0e10cSrcweir 	//--------------------------------------------------------------------
108*cdf0e10cSrcweir     namespace
109*cdf0e10cSrcweir     {
110*cdf0e10cSrcweir 	    //................................................................
111*cdf0e10cSrcweir         static void lcl_construct( DatabaseMetaData_Impl& _metaDataImpl, const Reference< XConnection >& _connection )
112*cdf0e10cSrcweir         {
113*cdf0e10cSrcweir             _metaDataImpl.xConnection = _connection;
114*cdf0e10cSrcweir             if ( !_metaDataImpl.xConnection.is() )
115*cdf0e10cSrcweir                 return;
116*cdf0e10cSrcweir 
117*cdf0e10cSrcweir             _metaDataImpl.xConnectionMetaData = _connection->getMetaData();
118*cdf0e10cSrcweir             if ( !_metaDataImpl.xConnectionMetaData.is() )
119*cdf0e10cSrcweir                 throw IllegalArgumentException();
120*cdf0e10cSrcweir         }
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir 	    //................................................................
123*cdf0e10cSrcweir         static void lcl_checkConnected( const DatabaseMetaData_Impl& _metaDataImpl )
124*cdf0e10cSrcweir         {
125*cdf0e10cSrcweir             if ( !_metaDataImpl.xConnection.is() || !_metaDataImpl.xConnectionMetaData.is() )
126*cdf0e10cSrcweir             {
127*cdf0e10cSrcweir                 ::connectivity::SharedResources aResources;
128*cdf0e10cSrcweir                 const ::rtl::OUString sError( aResources.getResourceString(STR_NO_CONNECTION_GIVEN));
129*cdf0e10cSrcweir                 throwSQLException( sError, SQL_CONNECTION_DOES_NOT_EXIST, NULL );
130*cdf0e10cSrcweir             }
131*cdf0e10cSrcweir         }
132*cdf0e10cSrcweir 
133*cdf0e10cSrcweir 	    //................................................................
134*cdf0e10cSrcweir         static bool lcl_getDriverSetting( const sal_Char* _asciiName, const DatabaseMetaData_Impl& _metaData, Any& _out_setting )
135*cdf0e10cSrcweir         {
136*cdf0e10cSrcweir             lcl_checkConnected( _metaData );
137*cdf0e10cSrcweir             const ::comphelper::NamedValueCollection& rDriverMetaData = _metaData.aDriverConfig.getMetaData( _metaData.xConnectionMetaData->getURL() );
138*cdf0e10cSrcweir             if ( !rDriverMetaData.has( _asciiName ) )
139*cdf0e10cSrcweir                 return false;
140*cdf0e10cSrcweir             _out_setting = rDriverMetaData.get( _asciiName );
141*cdf0e10cSrcweir             return true;
142*cdf0e10cSrcweir         }
143*cdf0e10cSrcweir 
144*cdf0e10cSrcweir 	    //................................................................
145*cdf0e10cSrcweir         static bool lcl_getConnectionSetting( const sal_Char* _asciiName, const DatabaseMetaData_Impl& _metaData, Any& _out_setting )
146*cdf0e10cSrcweir         {
147*cdf0e10cSrcweir             try
148*cdf0e10cSrcweir             {
149*cdf0e10cSrcweir                 Reference< XChild > xConnectionAsChild( _metaData.xConnection, UNO_QUERY );
150*cdf0e10cSrcweir                 if ( xConnectionAsChild.is() )
151*cdf0e10cSrcweir                 {
152*cdf0e10cSrcweir                     Reference< XPropertySet > xDataSource( xConnectionAsChild->getParent(), UNO_QUERY_THROW );
153*cdf0e10cSrcweir                     Reference< XPropertySet > xDataSourceSettings(
154*cdf0e10cSrcweir                         xDataSource->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Settings" ) ) ),
155*cdf0e10cSrcweir                         UNO_QUERY_THROW );
156*cdf0e10cSrcweir 
157*cdf0e10cSrcweir                     _out_setting = xDataSourceSettings->getPropertyValue( ::rtl::OUString::createFromAscii( _asciiName ) );
158*cdf0e10cSrcweir                 }
159*cdf0e10cSrcweir                 else
160*cdf0e10cSrcweir                 {
161*cdf0e10cSrcweir                     Reference< XDatabaseMetaData2 > xExtendedMetaData( _metaData.xConnectionMetaData, UNO_QUERY_THROW );
162*cdf0e10cSrcweir                     ::comphelper::NamedValueCollection aSettings( xExtendedMetaData->getConnectionInfo() );
163*cdf0e10cSrcweir                     _out_setting = aSettings.get( _asciiName );
164*cdf0e10cSrcweir                     return _out_setting.hasValue();
165*cdf0e10cSrcweir                 }
166*cdf0e10cSrcweir                 return true;
167*cdf0e10cSrcweir             }
168*cdf0e10cSrcweir             catch( const Exception& )
169*cdf0e10cSrcweir             {
170*cdf0e10cSrcweir             	DBG_UNHANDLED_EXCEPTION();
171*cdf0e10cSrcweir             }
172*cdf0e10cSrcweir             return false;
173*cdf0e10cSrcweir         }
174*cdf0e10cSrcweir 
175*cdf0e10cSrcweir         //................................................................
176*cdf0e10cSrcweir         static const ::rtl::OUString& lcl_getConnectionStringSetting(
177*cdf0e10cSrcweir             const DatabaseMetaData_Impl& _metaData, ::boost::optional< ::rtl::OUString >& _cachedSetting,
178*cdf0e10cSrcweir             ::rtl::OUString (SAL_CALL XDatabaseMetaData::*_getter)() )
179*cdf0e10cSrcweir         {
180*cdf0e10cSrcweir             if ( !_cachedSetting )
181*cdf0e10cSrcweir             {
182*cdf0e10cSrcweir                 lcl_checkConnected( _metaData );
183*cdf0e10cSrcweir                 try
184*cdf0e10cSrcweir                 {
185*cdf0e10cSrcweir                     _cachedSetting.reset( (_metaData.xConnectionMetaData.get()->*_getter)() );
186*cdf0e10cSrcweir                 }
187*cdf0e10cSrcweir                 catch( const Exception& ) { DBG_UNHANDLED_EXCEPTION(); }
188*cdf0e10cSrcweir             }
189*cdf0e10cSrcweir             return *_cachedSetting;
190*cdf0e10cSrcweir         }
191*cdf0e10cSrcweir     }
192*cdf0e10cSrcweir 
193*cdf0e10cSrcweir 	//====================================================================
194*cdf0e10cSrcweir 	//= DatabaseMetaData
195*cdf0e10cSrcweir 	//====================================================================
196*cdf0e10cSrcweir 	//--------------------------------------------------------------------
197*cdf0e10cSrcweir     DatabaseMetaData::DatabaseMetaData()
198*cdf0e10cSrcweir         :m_pImpl( new DatabaseMetaData_Impl )
199*cdf0e10cSrcweir     {
200*cdf0e10cSrcweir     }
201*cdf0e10cSrcweir 
202*cdf0e10cSrcweir 	//--------------------------------------------------------------------
203*cdf0e10cSrcweir     DatabaseMetaData::DatabaseMetaData( const Reference< XConnection >& _connection )
204*cdf0e10cSrcweir         :m_pImpl( new DatabaseMetaData_Impl )
205*cdf0e10cSrcweir     {
206*cdf0e10cSrcweir         lcl_construct( *m_pImpl, _connection );
207*cdf0e10cSrcweir     }
208*cdf0e10cSrcweir 
209*cdf0e10cSrcweir 	//--------------------------------------------------------------------
210*cdf0e10cSrcweir     DatabaseMetaData::DatabaseMetaData( const DatabaseMetaData& _copyFrom )
211*cdf0e10cSrcweir         :m_pImpl( new DatabaseMetaData_Impl( *_copyFrom.m_pImpl ) )
212*cdf0e10cSrcweir     {
213*cdf0e10cSrcweir     }
214*cdf0e10cSrcweir 
215*cdf0e10cSrcweir 	//--------------------------------------------------------------------
216*cdf0e10cSrcweir     DatabaseMetaData& DatabaseMetaData::operator=( const DatabaseMetaData& _copyFrom )
217*cdf0e10cSrcweir     {
218*cdf0e10cSrcweir         if ( this == &_copyFrom )
219*cdf0e10cSrcweir             return *this;
220*cdf0e10cSrcweir 
221*cdf0e10cSrcweir         m_pImpl.reset( new DatabaseMetaData_Impl( *_copyFrom.m_pImpl ) );
222*cdf0e10cSrcweir         return *this;
223*cdf0e10cSrcweir     }
224*cdf0e10cSrcweir 
225*cdf0e10cSrcweir 	//--------------------------------------------------------------------
226*cdf0e10cSrcweir     DatabaseMetaData::~DatabaseMetaData()
227*cdf0e10cSrcweir     {
228*cdf0e10cSrcweir     }
229*cdf0e10cSrcweir 
230*cdf0e10cSrcweir 	//--------------------------------------------------------------------
231*cdf0e10cSrcweir     bool DatabaseMetaData::isConnected() const
232*cdf0e10cSrcweir     {
233*cdf0e10cSrcweir         return m_pImpl->xConnection.is();
234*cdf0e10cSrcweir     }
235*cdf0e10cSrcweir 
236*cdf0e10cSrcweir     //--------------------------------------------------------------------
237*cdf0e10cSrcweir     bool DatabaseMetaData::supportsSubqueriesInFrom() const
238*cdf0e10cSrcweir     {
239*cdf0e10cSrcweir         lcl_checkConnected( *m_pImpl );
240*cdf0e10cSrcweir 
241*cdf0e10cSrcweir         bool supportsSubQueries = false;
242*cdf0e10cSrcweir         try
243*cdf0e10cSrcweir         {
244*cdf0e10cSrcweir             sal_Int32 maxTablesInselect = m_pImpl->xConnectionMetaData->getMaxTablesInSelect();
245*cdf0e10cSrcweir             supportsSubQueries = ( maxTablesInselect > 1 ) || ( maxTablesInselect == 0 );
246*cdf0e10cSrcweir             // TODO: is there a better way to determine this? The above is not really true. More precise,
247*cdf0e10cSrcweir             // it's a *very* generous heuristics ...
248*cdf0e10cSrcweir         }
249*cdf0e10cSrcweir         catch( const Exception& )
250*cdf0e10cSrcweir         {
251*cdf0e10cSrcweir         	DBG_UNHANDLED_EXCEPTION();
252*cdf0e10cSrcweir         }
253*cdf0e10cSrcweir         return supportsSubQueries;
254*cdf0e10cSrcweir     }
255*cdf0e10cSrcweir 
256*cdf0e10cSrcweir     //--------------------------------------------------------------------
257*cdf0e10cSrcweir     bool DatabaseMetaData::supportsPrimaryKeys() const
258*cdf0e10cSrcweir     {
259*cdf0e10cSrcweir         lcl_checkConnected( *m_pImpl );
260*cdf0e10cSrcweir 
261*cdf0e10cSrcweir         bool doesSupportPrimaryKeys = false;
262*cdf0e10cSrcweir         try
263*cdf0e10cSrcweir         {
264*cdf0e10cSrcweir             Any setting;
265*cdf0e10cSrcweir             if  (   !( lcl_getConnectionSetting( "PrimaryKeySupport", *m_pImpl, setting ) )
266*cdf0e10cSrcweir                 ||  !( setting >>= doesSupportPrimaryKeys )
267*cdf0e10cSrcweir                 )
268*cdf0e10cSrcweir                 doesSupportPrimaryKeys = m_pImpl->xConnectionMetaData->supportsCoreSQLGrammar();
269*cdf0e10cSrcweir         }
270*cdf0e10cSrcweir         catch( const Exception& )
271*cdf0e10cSrcweir         {
272*cdf0e10cSrcweir         	DBG_UNHANDLED_EXCEPTION();
273*cdf0e10cSrcweir         }
274*cdf0e10cSrcweir         return doesSupportPrimaryKeys;
275*cdf0e10cSrcweir     }
276*cdf0e10cSrcweir 
277*cdf0e10cSrcweir     //--------------------------------------------------------------------
278*cdf0e10cSrcweir     const ::rtl::OUString&  DatabaseMetaData::getIdentifierQuoteString() const
279*cdf0e10cSrcweir     {
280*cdf0e10cSrcweir         return lcl_getConnectionStringSetting( *m_pImpl, m_pImpl->sCachedIdentifierQuoteString, &XDatabaseMetaData::getIdentifierQuoteString );
281*cdf0e10cSrcweir     }
282*cdf0e10cSrcweir 
283*cdf0e10cSrcweir     //--------------------------------------------------------------------
284*cdf0e10cSrcweir     const ::rtl::OUString&  DatabaseMetaData::getCatalogSeparator() const
285*cdf0e10cSrcweir     {
286*cdf0e10cSrcweir         return lcl_getConnectionStringSetting( *m_pImpl, m_pImpl->sCachedCatalogSeparator, &XDatabaseMetaData::getCatalogSeparator );
287*cdf0e10cSrcweir     }
288*cdf0e10cSrcweir 
289*cdf0e10cSrcweir     //--------------------------------------------------------------------
290*cdf0e10cSrcweir     bool DatabaseMetaData::restrictIdentifiersToSQL92() const
291*cdf0e10cSrcweir     {
292*cdf0e10cSrcweir         lcl_checkConnected( *m_pImpl );
293*cdf0e10cSrcweir 
294*cdf0e10cSrcweir         bool restrict( false );
295*cdf0e10cSrcweir         Any setting;
296*cdf0e10cSrcweir         if ( lcl_getConnectionSetting( "EnableSQL92Check", *m_pImpl, setting ) )
297*cdf0e10cSrcweir             OSL_VERIFY( setting >>= restrict );
298*cdf0e10cSrcweir         return restrict;
299*cdf0e10cSrcweir     }
300*cdf0e10cSrcweir 
301*cdf0e10cSrcweir     //--------------------------------------------------------------------
302*cdf0e10cSrcweir     bool DatabaseMetaData::generateASBeforeCorrelationName() const
303*cdf0e10cSrcweir     {
304*cdf0e10cSrcweir         bool doGenerate( true );
305*cdf0e10cSrcweir         Any setting;
306*cdf0e10cSrcweir         if ( lcl_getConnectionSetting( "GenerateASBeforeCorrelationName", *m_pImpl, setting ) )
307*cdf0e10cSrcweir             OSL_VERIFY( setting >>= doGenerate );
308*cdf0e10cSrcweir         return doGenerate;
309*cdf0e10cSrcweir     }
310*cdf0e10cSrcweir     //--------------------------------------------------------------------
311*cdf0e10cSrcweir     bool DatabaseMetaData::shouldEscapeDateTime() const
312*cdf0e10cSrcweir     {
313*cdf0e10cSrcweir         bool doGenerate( true );
314*cdf0e10cSrcweir         Any setting;
315*cdf0e10cSrcweir         if ( lcl_getConnectionSetting( "EscapeDateTime", *m_pImpl, setting ) )
316*cdf0e10cSrcweir             OSL_VERIFY( setting >>= doGenerate );
317*cdf0e10cSrcweir         return doGenerate;
318*cdf0e10cSrcweir     }
319*cdf0e10cSrcweir     //--------------------------------------------------------------------
320*cdf0e10cSrcweir     bool DatabaseMetaData::isAutoIncrementPrimaryKey() const
321*cdf0e10cSrcweir     {
322*cdf0e10cSrcweir         bool is( true );
323*cdf0e10cSrcweir         Any setting;
324*cdf0e10cSrcweir         if ( lcl_getDriverSetting( "AutoIncrementIsPrimaryKey", *m_pImpl, setting ) )
325*cdf0e10cSrcweir             OSL_VERIFY( setting >>= is );
326*cdf0e10cSrcweir         return is;
327*cdf0e10cSrcweir     }
328*cdf0e10cSrcweir     //--------------------------------------------------------------------
329*cdf0e10cSrcweir     sal_Int32 DatabaseMetaData::getBooleanComparisonMode() const
330*cdf0e10cSrcweir     {
331*cdf0e10cSrcweir         sal_Int32 mode( BooleanComparisonMode::EQUAL_INTEGER );
332*cdf0e10cSrcweir         Any setting;
333*cdf0e10cSrcweir         if ( lcl_getConnectionSetting( "BooleanComparisonMode", *m_pImpl, setting ) )
334*cdf0e10cSrcweir             OSL_VERIFY( setting >>= mode );
335*cdf0e10cSrcweir         return mode;
336*cdf0e10cSrcweir     }
337*cdf0e10cSrcweir     //--------------------------------------------------------------------
338*cdf0e10cSrcweir     bool DatabaseMetaData::supportsRelations() const
339*cdf0e10cSrcweir     {
340*cdf0e10cSrcweir         lcl_checkConnected( *m_pImpl );
341*cdf0e10cSrcweir         bool bSupport = false;
342*cdf0e10cSrcweir         try
343*cdf0e10cSrcweir         {
344*cdf0e10cSrcweir             bSupport = m_pImpl->xConnectionMetaData->supportsIntegrityEnhancementFacility();
345*cdf0e10cSrcweir         }
346*cdf0e10cSrcweir         catch( const Exception& )
347*cdf0e10cSrcweir         {
348*cdf0e10cSrcweir             DBG_UNHANDLED_EXCEPTION();
349*cdf0e10cSrcweir         }
350*cdf0e10cSrcweir         try
351*cdf0e10cSrcweir         {
352*cdf0e10cSrcweir             if ( !bSupport )
353*cdf0e10cSrcweir             {
354*cdf0e10cSrcweir                 const ::rtl::OUString url = m_pImpl->xConnectionMetaData->getURL();
355*cdf0e10cSrcweir                 char pMySQL[] = "sdbc:mysql";
356*cdf0e10cSrcweir 			    bSupport = url.matchAsciiL(pMySQL,(sizeof(pMySQL)/sizeof(pMySQL[0]))-1);
357*cdf0e10cSrcweir             }
358*cdf0e10cSrcweir         }
359*cdf0e10cSrcweir         catch( const Exception& )
360*cdf0e10cSrcweir         {
361*cdf0e10cSrcweir         	DBG_UNHANDLED_EXCEPTION();
362*cdf0e10cSrcweir         }
363*cdf0e10cSrcweir         return bSupport;
364*cdf0e10cSrcweir     }
365*cdf0e10cSrcweir 
366*cdf0e10cSrcweir     //--------------------------------------------------------------------
367*cdf0e10cSrcweir     bool DatabaseMetaData::supportsColumnAliasInOrderBy() const
368*cdf0e10cSrcweir     {
369*cdf0e10cSrcweir         bool doGenerate( true );
370*cdf0e10cSrcweir         Any setting;
371*cdf0e10cSrcweir         if ( lcl_getConnectionSetting( "ColumnAliasInOrderBy", *m_pImpl, setting ) )
372*cdf0e10cSrcweir             OSL_VERIFY( setting >>= doGenerate );
373*cdf0e10cSrcweir         return doGenerate;
374*cdf0e10cSrcweir     }
375*cdf0e10cSrcweir 
376*cdf0e10cSrcweir     //--------------------------------------------------------------------
377*cdf0e10cSrcweir     bool DatabaseMetaData::supportsUserAdministration( const ::comphelper::ComponentContext& _rContext ) const
378*cdf0e10cSrcweir     {
379*cdf0e10cSrcweir         lcl_checkConnected( *m_pImpl  );
380*cdf0e10cSrcweir 
381*cdf0e10cSrcweir         bool isSupported( false );
382*cdf0e10cSrcweir         try
383*cdf0e10cSrcweir         {
384*cdf0e10cSrcweir             // find the XUsersSupplier interface
385*cdf0e10cSrcweir             // - either directly at the connection
386*cdf0e10cSrcweir             Reference< XUsersSupplier > xUsersSupp( m_pImpl->xConnection, UNO_QUERY );
387*cdf0e10cSrcweir             if ( !xUsersSupp.is() )
388*cdf0e10cSrcweir             {
389*cdf0e10cSrcweir                 // - or at the driver manager
390*cdf0e10cSrcweir 	            Reference< XDriverAccess > xDriverManager(
391*cdf0e10cSrcweir                     _rContext.createComponent( "com.sun.star.sdbc.DriverManager" ), UNO_QUERY_THROW );
392*cdf0e10cSrcweir                 Reference< XDataDefinitionSupplier > xDriver( xDriverManager->getDriverByURL( m_pImpl->xConnectionMetaData->getURL() ), UNO_QUERY );
393*cdf0e10cSrcweir                 if ( xDriver.is() )
394*cdf0e10cSrcweir                     xUsersSupp.set( xDriver->getDataDefinitionByConnection( m_pImpl->xConnection ), UNO_QUERY );
395*cdf0e10cSrcweir             }
396*cdf0e10cSrcweir 
397*cdf0e10cSrcweir             isSupported = ( xUsersSupp.is() && xUsersSupp->getUsers().is() );
398*cdf0e10cSrcweir         }
399*cdf0e10cSrcweir         catch( const Exception& )
400*cdf0e10cSrcweir         {
401*cdf0e10cSrcweir         	DBG_UNHANDLED_EXCEPTION();
402*cdf0e10cSrcweir         }
403*cdf0e10cSrcweir         return isSupported;
404*cdf0e10cSrcweir     }
405*cdf0e10cSrcweir 
406*cdf0e10cSrcweir     //--------------------------------------------------------------------
407*cdf0e10cSrcweir     bool DatabaseMetaData::displayEmptyTableFolders() const
408*cdf0e10cSrcweir     {
409*cdf0e10cSrcweir         bool doDisplay( true );
410*cdf0e10cSrcweir #ifdef IMPLEMENTED_LATER
411*cdf0e10cSrcweir         Any setting;
412*cdf0e10cSrcweir         if ( lcl_getConnectionSetting( "DisplayEmptyTableFolders", *m_pImpl, setting ) )
413*cdf0e10cSrcweir             OSL_VERIFY( setting >>= doDisplay );
414*cdf0e10cSrcweir #else
415*cdf0e10cSrcweir         try
416*cdf0e10cSrcweir         {
417*cdf0e10cSrcweir             Reference< XDatabaseMetaData > xMeta( m_pImpl->xConnectionMetaData, UNO_SET_THROW );
418*cdf0e10cSrcweir             ::rtl::OUString sConnectionURL( xMeta->getURL() );
419*cdf0e10cSrcweir             doDisplay = sConnectionURL.compareToAscii( RTL_CONSTASCII_STRINGPARAM( "sdbc:mysql:mysqlc" ) ) == 0;
420*cdf0e10cSrcweir         }
421*cdf0e10cSrcweir         catch( const Exception& )
422*cdf0e10cSrcweir         {
423*cdf0e10cSrcweir         	DBG_UNHANDLED_EXCEPTION();
424*cdf0e10cSrcweir         }
425*cdf0e10cSrcweir #endif
426*cdf0e10cSrcweir         return doDisplay;
427*cdf0e10cSrcweir     }
428*cdf0e10cSrcweir     //--------------------------------------------------------------------
429*cdf0e10cSrcweir     bool DatabaseMetaData::supportsThreads() const
430*cdf0e10cSrcweir     {
431*cdf0e10cSrcweir         bool bSupported( true );
432*cdf0e10cSrcweir         try
433*cdf0e10cSrcweir         {
434*cdf0e10cSrcweir             Reference< XDatabaseMetaData > xMeta( m_pImpl->xConnectionMetaData, UNO_SET_THROW );
435*cdf0e10cSrcweir             ::rtl::OUString sConnectionURL( xMeta->getURL() );
436*cdf0e10cSrcweir             bSupported = sConnectionURL.compareToAscii( RTL_CONSTASCII_STRINGPARAM( "sdbc:mysql:mysqlc" ) ) != 0;
437*cdf0e10cSrcweir         }
438*cdf0e10cSrcweir         catch( const Exception& )
439*cdf0e10cSrcweir         {
440*cdf0e10cSrcweir         	DBG_UNHANDLED_EXCEPTION();
441*cdf0e10cSrcweir         }
442*cdf0e10cSrcweir         return bSupported;
443*cdf0e10cSrcweir     }
444*cdf0e10cSrcweir 
445*cdf0e10cSrcweir //........................................................................
446*cdf0e10cSrcweir } // namespace dbtools
447*cdf0e10cSrcweir //........................................................................
448*cdf0e10cSrcweir 
449