27#include <com/sun/star/lang/IllegalArgumentException.hpp>
28#include <com/sun/star/container/XChild.hpp>
29#include <com/sun/star/beans/XPropertySet.hpp>
30#include <com/sun/star/sdb/BooleanComparisonMode.hpp>
31#include <com/sun/star/sdbc/XDatabaseMetaData2.hpp>
32#include <com/sun/star/sdbcx/XUsersSupplier.hpp>
33#include <com/sun/star/sdbcx/XDataDefinitionSupplier.hpp>
34#include <com/sun/star/sdbc/DriverManager.hpp>
48 using ::com::sun::star::uno::Reference;
49 using ::com::sun::star::sdbc::XConnection;
50 using ::com::sun::star::sdbc::XDatabaseMetaData;
51 using ::com::sun::star::sdbc::XDatabaseMetaData2;
52 using ::com::sun::star::lang::IllegalArgumentException;
53 using ::com::sun::star::uno::Exception;
54 using ::com::sun::star::uno::Any;
55 using ::com::sun::star::uno::XComponentContext;
56 using ::com::sun::star::container::XChild;
57 using ::com::sun::star::uno::UNO_QUERY_THROW;
58 using ::com::sun::star::beans::XPropertySet;
59 using ::com::sun::star::uno::UNO_QUERY;
60 using ::com::sun::star::sdbcx::XUsersSupplier;
61 using ::com::sun::star::sdbcx::XDataDefinitionSupplier;
62 using ::com::sun::star::sdbc::DriverManager;
63 using ::com::sun::star::sdbc::XDriverManager2;
64 using ::com::sun::star::uno::UNO_SET_THROW;
66 namespace BooleanComparisonMode = ::com::sun::star::sdb::BooleanComparisonMode;
87 void lcl_construct( DatabaseMetaData_Impl& _metaDataImpl,
const Reference< XConnection >& _connection )
89 _metaDataImpl.xConnection = _connection;
90 if ( !_metaDataImpl.xConnection.is() )
93 _metaDataImpl.xConnectionMetaData = _connection->
getMetaData();
94 if ( !_metaDataImpl.xConnectionMetaData.is() )
95 throw IllegalArgumentException();
99 void lcl_checkConnected(
const DatabaseMetaData_Impl& _metaDataImpl )
101 if ( !_metaDataImpl.xConnection.is() || !_metaDataImpl.xConnectionMetaData.is() )
110 bool lcl_getDriverSetting(
const OUString& _asciiName,
const DatabaseMetaData_Impl& _metaData, Any& _out_setting )
112 lcl_checkConnected( _metaData );
113 const ::comphelper::NamedValueCollection& rDriverMetaData = _metaData.aDriverConfig.getMetaData( _metaData.xConnectionMetaData->getURL() );
114 if ( !rDriverMetaData.has( _asciiName ) )
116 _out_setting = rDriverMetaData.get( _asciiName );
121 bool lcl_getConnectionSetting(
const OUString& _asciiName,
const DatabaseMetaData_Impl& _metaData, Any& _out_setting )
125 Reference< XChild > xConnectionAsChild( _metaData.xConnection, UNO_QUERY );
126 if ( xConnectionAsChild.is() )
128 Reference< XPropertySet > xDataSource( xConnectionAsChild->getParent(), UNO_QUERY_THROW );
129 Reference< XPropertySet > xDataSourceSettings(
130 xDataSource->getPropertyValue(
"Settings"),
133 _out_setting = xDataSourceSettings->getPropertyValue( _asciiName );
137 Reference< XDatabaseMetaData2 > xExtendedMetaData( _metaData.xConnectionMetaData, UNO_QUERY_THROW );
139 return _out_setting.hasValue();
143 catch(
const Exception& )
151 const OUString& lcl_getConnectionStringSetting(
152 const DatabaseMetaData_Impl& _metaData, ::std::optional< OUString >& _cachedSetting,
153 OUString (SAL_CALL XDatabaseMetaData::*_getter)() )
155 if ( !_cachedSetting )
157 lcl_checkConnected( _metaData );
160 _cachedSetting = (_metaData.xConnectionMetaData.get()->*_getter)();
164 return *_cachedSetting;
176 lcl_construct( *
m_pImpl, _connection );
186 :
m_pImpl(std::move(_copyFrom.m_pImpl))
192 if (
this == &_copyFrom )
201 m_pImpl = std::move(_copyFrom.m_pImpl);
211 return m_pImpl->xConnection.is();
217 lcl_checkConnected( *
m_pImpl );
219 bool bSupportsSubQueries =
false;
222 sal_Int32 maxTablesInselect =
m_pImpl->xConnectionMetaData->getMaxTablesInSelect();
223 bSupportsSubQueries = ( maxTablesInselect > 1 ) || ( maxTablesInselect == 0 );
231 return bSupportsSubQueries;
237 lcl_checkConnected( *
m_pImpl );
239 bool bDoesSupportPrimaryKeys =
false;
243 if ( !( lcl_getConnectionSetting(
"PrimaryKeySupport", *
m_pImpl, setting ) )
244 || !( setting >>= bDoesSupportPrimaryKeys )
246 bDoesSupportPrimaryKeys =
m_pImpl->xConnectionMetaData->supportsCoreSQLGrammar()
247 ||
m_pImpl->xConnectionMetaData->supportsANSI92EntryLevelSQL();
253 return bDoesSupportPrimaryKeys;
259 return lcl_getConnectionStringSetting( *
m_pImpl,
m_pImpl->sCachedIdentifierQuoteString, &XDatabaseMetaData::getIdentifierQuoteString );
265 return lcl_getConnectionStringSetting( *
m_pImpl,
m_pImpl->sCachedCatalogSeparator, &XDatabaseMetaData::getCatalogSeparator );
271 lcl_checkConnected( *
m_pImpl );
273 bool restrict(
false );
275 if ( lcl_getConnectionSetting(
"EnableSQL92Check", *
m_pImpl, setting ) )
276 if( ! (setting >>= restrict) )
277 SAL_WARN(
"connectivity.commontools",
"restrictIdentifiersToSQL92: unable to assign EnableSQL92Check");
284 bool doGenerate(
false );
286 if ( lcl_getConnectionSetting(
"GenerateASBeforeCorrelationName", *
m_pImpl, setting ) )
287 if( ! (setting >>= doGenerate) )
288 SAL_WARN(
"connectivity.commontools",
"generateASBeforeCorrelationName: unable to assign GenerateASBeforeCorrelationName");
294 bool doGenerate(
true );
296 if ( lcl_getConnectionSetting(
"EscapeDateTime", *
m_pImpl, setting ) )
297 if( ! (setting >>= doGenerate) )
298 SAL_WARN(
"connectivity.commontools",
"shouldEscapeDateTime: unable to assign EscapeDateTime");
304 bool doSubstitute(
true );
306 if ( lcl_getConnectionSetting(
"ParameterNameSubstitution", *
m_pImpl, setting ) )
307 if( ! (setting >>= doSubstitute) )
308 SAL_WARN(
"connectivity.commontools",
"shouldSubstituteParameterNames: unable to assign ParameterNameSubstitution");
316 if ( lcl_getDriverSetting(
"AutoIncrementIsPrimaryKey", *
m_pImpl, setting ) )
317 if( ! (setting >>= is) )
318 SAL_WARN(
"connectivity.commontools",
"isAutoIncrementPrimaryKey: unable to assign AutoIncrementIsPrimaryKey");
324 sal_Int32
mode( BooleanComparisonMode::EQUAL_INTEGER );
326 if ( lcl_getConnectionSetting(
"BooleanComparisonMode", *
m_pImpl, setting ) )
327 if( ! (setting >>=
mode) )
328 SAL_WARN(
"connectivity.commontools",
"getBooleanComparisonMode: unable to assign BooleanComparisonMode");
334 lcl_checkConnected( *
m_pImpl );
335 bool bSupport =
false;
338 bSupport =
m_pImpl->xConnectionMetaData->supportsIntegrityEnhancementFacility();
348 const OUString url =
m_pImpl->xConnectionMetaData->getURL();
349 bSupport = url.startsWith(
"sdbc:mysql");
362 bool doGenerate(
true );
364 if ( lcl_getConnectionSetting(
"ColumnAliasInOrderBy", *
m_pImpl, setting ) )
365 if( ! (setting >>= doGenerate) )
366 SAL_WARN(
"connectivity.commontools",
"supportsColumnAliasInOrderBy: unable to assign ColumnAliasInOrderBy");
373 lcl_checkConnected( *
m_pImpl );
375 bool isSupported(
false );
380 Reference< XUsersSupplier > xUsersSupp(
m_pImpl->xConnection, UNO_QUERY );
381 if ( !xUsersSupp.is() )
384 Reference< XDriverManager2 > xDriverManager = DriverManager::create( _rContext );
385 Reference< XDataDefinitionSupplier > xDriver( xDriverManager->getDriverByURL(
m_pImpl->xConnectionMetaData->getURL() ), UNO_QUERY );
387 xUsersSupp.set( xDriver->getDataDefinitionByConnection(
m_pImpl->xConnection ), UNO_QUERY );
390 isSupported = ( xUsersSupp.is() && xUsersSupp->getUsers().is() );
402 bool doDisplay(
true );
403#ifdef IMPLEMENTED_LATER
405 if ( lcl_getConnectionSetting(
"DisplayEmptyTableFolders", *
m_pImpl, setting ) )
406 if( ! (setting >>= doDisplay) )
407 SAL_WARN(
"connectivity.commontools",
"displayEmptyTableFolders: unable to assign DisplayEmptyTableFolders");
411 Reference< XDatabaseMetaData > xMeta(
m_pImpl->xConnectionMetaData, UNO_SET_THROW );
412 OUString sConnectionURL( xMeta->getURL() );
413 doDisplay = sConnectionURL.startsWith(
"sdbc:mysql:mysqlc" );
425 bool bSupported(
true );
428 Reference< XDatabaseMetaData > xMeta(
m_pImpl->xConnectionMetaData, UNO_SET_THROW );
429 OUString sConnectionURL( xMeta->getURL() );
430 bSupported = !sConnectionURL.startsWith(
"sdbc:mysql:mysqlc" );
const css::uno::Any & get(const OUString &_rValueName) const
const ::comphelper::NamedValueCollection & getMetaData(std::u16string_view _sURL) const
helper class for accessing resources shared by different libraries in the connectivity module
OUString getResourceString(TranslateId pResId) const
loads a string from the shared resource file
#define DBG_UNHANDLED_EXCEPTION(...)
#define SAL_WARN(area, stream)
Reference< XComponentContext > getProcessComponentContext()