2009-10-12 12:21:44 +0200 msc r276827 : remove warning for issue 102712 because the issue is fixed 2009-10-05 07:14:20 +0200 oj r276658 : #105585# add missing dependency for OOO_UI 2009-10-02 12:50:19 +0200 fs r276632 : #i105505# If a model is created, and is a revenant of a previous incarnation, then ensure it is properly initialized. In particular, in its ctor, set the state to "Initializing", not "Initialized", and then let the ModelImpl call attachResource. This ensures that the model is initialized completely, including firing the necessary events. 2009-10-02 12:46:12 +0200 fs r276631 : #i105505# always do an attachResource at the newly loaded model, even if it (internally) was not really loaded, but only a revenant of a previous incarnation of this document 2009-10-01 13:09:07 +0200 fs r276596 : do not rely on the name 'Standard' for the one and only form in a document 2009-10-01 12:35:56 +0200 fs r276589 : #i105509# don't rely on default form component names, use indexes 2009-10-01 11:19:18 +0200 fs r276584 : copying the fix for #i105082# into this CWS 2009-10-01 11:13:22 +0200 fs r276583 : improved logs 2009-10-01 11:10:44 +0200 fs r276581 : #i105505# 2009-10-01 08:07:57 +0200 fs r276575 : manual merge of trunk, to allow cwslocalize to run 2009-09-30 22:48:30 +0200 fs r276574 : removed that strange ONLOAD definition 2009-09-30 12:58:18 +0200 fs r276553 : copy fix for #i105387# into this CWS, as the issue prevents us from finalizing the CWS 2009-09-30 12:56:45 +0200 fs r276552 : copy fix for #i105387# into this CWS, as the issue prevents us from finalizing the CWS 2009-09-30 11:47:45 +0200 fs r276549 : #i105235# 2009-09-29 12:27:40 +0200 fs r276521 : #i105367# 2009-09-28 12:08:17 +0200 oj r276485 : #i105371# export version in manifest.xml as well 2009-09-28 12:07:02 +0200 oj r276484 : #i105371# export version in manifest.xml as well 2009-09-28 09:48:01 +0200 oj r276481 : #i105366# init drivers when not empty 2009-09-25 14:31:27 +0200 fs r276466 : CWS-TOOLING: rebase CWS dba32h to trunk@276429 (milestone: DEV300:m60) 2009-09-24 13:52:54 +0200 fs r276422 : #i105234# do not zoom the control when they view information is still uninitialized (happens at least in Writer when opening a form document) 2009-09-24 11:42:03 +0200 fs r276413 : #i105234# proper zoom handling for the nav bar 2009-09-24 11:41:40 +0200 fs r276412 : #i105234# setZoom: care for precision errors caused by implicit conversion float->double 2009-09-23 12:21:22 +0200 oj r276377 : remove dos lineends 2009-09-23 11:44:52 +0200 oj r276376 : #i105216# load config on demand 2009-09-23 11:44:19 +0200 oj r276375 : #i105216# load config on demand 2009-09-23 11:43:35 +0200 oj r276374 : #i105216# load config on demand 2009-09-21 09:13:03 +0200 oj r276307 : #i105158# use Thread support 2009-09-18 13:06:50 +0200 fs r276277 : #i105147# 2009-09-18 11:48:23 +0200 oj r276271 : #i105158# new method for thread safety 2009-09-18 10:42:56 +0200 fs r276266 : CWS-TOOLING: rebase CWS dba32h to trunk@276192 (milestone: DEV300:m59) 2009-09-18 08:30:03 +0200 oj r276263 : #i105016# load correct ldap so 2009-09-17 13:42:31 +0200 oj r276240 : change count of check boxes 2009-09-17 13:32:59 +0200 oj r276239 : revert false to true for currency 2009-09-17 09:14:46 +0200 oj r276220 : #i104901# add patch for every issue 2009-09-17 09:10:29 +0200 oj r276219 : #i104901# add patch for every issue 2009-09-11 13:47:49 +0200 oj r276060 : #i104901# fix for indentity 2009-09-11 12:14:14 +0200 fs r276056 : #i104594# allow to render controls without an SdrPageView 2009-09-11 11:49:31 +0200 fs r276055 : CWS-TOOLING: rebase CWS dba32h to trunk@276043 (milestone: DEV300:m58) 2009-09-10 08:41:40 +0200 oj r276021 : #i104911# export variable-set not for repeating sections
431 lines
17 KiB
C++
431 lines
17 KiB
C++
/*************************************************************************
|
|
*
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
*
|
|
* Copyright 2008 by Sun Microsystems, Inc.
|
|
*
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
|
*
|
|
* $RCSfile: dbmetadata.cxx,v $
|
|
* $Revision: 1.10.22.1 $
|
|
*
|
|
* This file is part of OpenOffice.org.
|
|
*
|
|
* OpenOffice.org is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU Lesser General Public License version 3
|
|
* only, as published by the Free Software Foundation.
|
|
*
|
|
* OpenOffice.org is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU Lesser General Public License version 3 for more details
|
|
* (a copy is included in the LICENSE file that accompanied this code).
|
|
*
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
* version 3 along with OpenOffice.org. If not, see
|
|
* <http://www.openoffice.org/license.html>
|
|
* for a copy of the LGPLv3 License.
|
|
*
|
|
************************************************************************/
|
|
|
|
// MARKER(update_precomp.py): autogen include statement, do not remove
|
|
#include "precompiled_connectivity.hxx"
|
|
|
|
#include "connectivity/dbmetadata.hxx"
|
|
#include "connectivity/dbexception.hxx"
|
|
#include "connectivity/DriversConfig.hxx"
|
|
#include "resource/common_res.hrc"
|
|
#include "resource/sharedresources.hxx"
|
|
|
|
/** === begin UNO includes === **/
|
|
#include <com/sun/star/lang/IllegalArgumentException.hpp>
|
|
#include <com/sun/star/container/XChild.hpp>
|
|
#include <com/sun/star/beans/XPropertySet.hpp>
|
|
#include <com/sun/star/beans/PropertyValue.hpp>
|
|
#include <com/sun/star/beans/XPropertySetInfo.hpp>
|
|
#include <com/sun/star/sdb/BooleanComparisonMode.hpp>
|
|
#include <com/sun/star/sdbc/XDatabaseMetaData2.hpp>
|
|
#include <com/sun/star/sdbcx/XUsersSupplier.hpp>
|
|
#include <com/sun/star/sdbcx/XDataDefinitionSupplier.hpp>
|
|
#include <com/sun/star/sdbc/XDriverAccess.hpp>
|
|
/** === end UNO includes === **/
|
|
|
|
#include <tools/diagnose_ex.h>
|
|
#include <comphelper/namedvaluecollection.hxx>
|
|
#include <comphelper/componentcontext.hxx>
|
|
#include <comphelper/processfactory.hxx>
|
|
|
|
#include <boost/optional.hpp>
|
|
|
|
//........................................................................
|
|
namespace dbtools
|
|
{
|
|
//........................................................................
|
|
|
|
/** === begin UNO using === **/
|
|
using ::com::sun::star::uno::Reference;
|
|
using ::com::sun::star::sdbc::XConnection;
|
|
using ::com::sun::star::sdbc::XConnection;
|
|
using ::com::sun::star::sdbc::XDatabaseMetaData;
|
|
using ::com::sun::star::sdbc::XDatabaseMetaData2;
|
|
using ::com::sun::star::lang::IllegalArgumentException;
|
|
using ::com::sun::star::uno::Exception;
|
|
using ::com::sun::star::uno::Any;
|
|
using ::com::sun::star::container::XChild;
|
|
using ::com::sun::star::uno::UNO_QUERY_THROW;
|
|
using ::com::sun::star::beans::XPropertySet;
|
|
using ::com::sun::star::uno::Sequence;
|
|
using ::com::sun::star::beans::PropertyValue;
|
|
using ::com::sun::star::beans::XPropertySetInfo;
|
|
using ::com::sun::star::uno::UNO_QUERY;
|
|
using ::com::sun::star::sdbcx::XUsersSupplier;
|
|
using ::com::sun::star::sdbcx::XDataDefinitionSupplier;
|
|
using ::com::sun::star::sdbc::XDriverAccess;
|
|
using ::com::sun::star::uno::UNO_SET_THROW;
|
|
/** === end UNO using === **/
|
|
namespace BooleanComparisonMode = ::com::sun::star::sdb::BooleanComparisonMode;
|
|
|
|
//====================================================================
|
|
//= DatabaseMetaData_Impl
|
|
//====================================================================
|
|
struct DatabaseMetaData_Impl
|
|
{
|
|
Reference< XConnection > xConnection;
|
|
Reference< XDatabaseMetaData > xConnectionMetaData;
|
|
::connectivity::DriversConfig aDriverConfig;
|
|
|
|
::boost::optional< ::rtl::OUString > sCachedIdentifierQuoteString;
|
|
::boost::optional< ::rtl::OUString > sCachedCatalogSeparator;
|
|
|
|
DatabaseMetaData_Impl()
|
|
:xConnection()
|
|
,xConnectionMetaData()
|
|
,aDriverConfig( ::comphelper::getProcessServiceFactory() )
|
|
,sCachedIdentifierQuoteString()
|
|
,sCachedCatalogSeparator()
|
|
{
|
|
}
|
|
};
|
|
|
|
//--------------------------------------------------------------------
|
|
namespace
|
|
{
|
|
//................................................................
|
|
static void lcl_construct( DatabaseMetaData_Impl& _metaDataImpl, const Reference< XConnection >& _connection )
|
|
{
|
|
_metaDataImpl.xConnection = _connection;
|
|
if ( !_metaDataImpl.xConnection.is() )
|
|
return;
|
|
|
|
_metaDataImpl.xConnectionMetaData = _connection->getMetaData();
|
|
if ( !_metaDataImpl.xConnectionMetaData.is() )
|
|
throw IllegalArgumentException();
|
|
}
|
|
|
|
//................................................................
|
|
static void lcl_checkConnected( const DatabaseMetaData_Impl& _metaDataImpl )
|
|
{
|
|
if ( !_metaDataImpl.xConnection.is() || !_metaDataImpl.xConnectionMetaData.is() )
|
|
{
|
|
::connectivity::SharedResources aResources;
|
|
const ::rtl::OUString sError( aResources.getResourceString(STR_NO_CONNECTION_GIVEN));
|
|
throwSQLException( sError, SQL_CONNECTION_DOES_NOT_EXIST, NULL );
|
|
}
|
|
}
|
|
|
|
//................................................................
|
|
static bool lcl_getDriverSetting( const sal_Char* _asciiName, const DatabaseMetaData_Impl& _metaData, Any& _out_setting )
|
|
{
|
|
lcl_checkConnected( _metaData );
|
|
const ::comphelper::NamedValueCollection& rDriverMetaData = _metaData.aDriverConfig.getMetaData( _metaData.xConnectionMetaData->getURL() );
|
|
if ( !rDriverMetaData.has( _asciiName ) )
|
|
return false;
|
|
_out_setting = rDriverMetaData.get( _asciiName );
|
|
return true;
|
|
}
|
|
|
|
//................................................................
|
|
static bool lcl_getConnectionSetting( const sal_Char* _asciiName, const DatabaseMetaData_Impl& _metaData, Any& _out_setting )
|
|
{
|
|
try
|
|
{
|
|
Reference< XChild > xConnectionAsChild( _metaData.xConnection, UNO_QUERY );
|
|
if ( xConnectionAsChild.is() )
|
|
{
|
|
Reference< XPropertySet > xDataSource( xConnectionAsChild->getParent(), UNO_QUERY_THROW );
|
|
Reference< XPropertySet > xDataSourceSettings(
|
|
xDataSource->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Settings" ) ) ),
|
|
UNO_QUERY_THROW );
|
|
|
|
_out_setting = xDataSourceSettings->getPropertyValue( ::rtl::OUString::createFromAscii( _asciiName ) );
|
|
}
|
|
else
|
|
{
|
|
Reference< XDatabaseMetaData2 > xExtendedMetaData( _metaData.xConnectionMetaData, UNO_QUERY_THROW );
|
|
::comphelper::NamedValueCollection aSettings( xExtendedMetaData->getConnectionInfo() );
|
|
_out_setting = aSettings.get( _asciiName );
|
|
return _out_setting.hasValue();
|
|
}
|
|
return true;
|
|
}
|
|
catch( const Exception& )
|
|
{
|
|
DBG_UNHANDLED_EXCEPTION();
|
|
}
|
|
return false;
|
|
}
|
|
|
|
//................................................................
|
|
static const ::rtl::OUString& lcl_getConnectionStringSetting(
|
|
const DatabaseMetaData_Impl& _metaData, ::boost::optional< ::rtl::OUString >& _cachedSetting,
|
|
::rtl::OUString (SAL_CALL XDatabaseMetaData::*_getter)() )
|
|
{
|
|
if ( !_cachedSetting )
|
|
{
|
|
lcl_checkConnected( _metaData );
|
|
try
|
|
{
|
|
_cachedSetting.reset( (_metaData.xConnectionMetaData.get()->*_getter)() );
|
|
}
|
|
catch( const Exception& ) { DBG_UNHANDLED_EXCEPTION(); }
|
|
}
|
|
return *_cachedSetting;
|
|
}
|
|
}
|
|
|
|
//====================================================================
|
|
//= DatabaseMetaData
|
|
//====================================================================
|
|
//--------------------------------------------------------------------
|
|
DatabaseMetaData::DatabaseMetaData()
|
|
:m_pImpl( new DatabaseMetaData_Impl )
|
|
{
|
|
}
|
|
|
|
//--------------------------------------------------------------------
|
|
DatabaseMetaData::DatabaseMetaData( const Reference< XConnection >& _connection )
|
|
:m_pImpl( new DatabaseMetaData_Impl )
|
|
{
|
|
lcl_construct( *m_pImpl, _connection );
|
|
}
|
|
|
|
//--------------------------------------------------------------------
|
|
DatabaseMetaData::DatabaseMetaData( const DatabaseMetaData& _copyFrom )
|
|
:m_pImpl( new DatabaseMetaData_Impl( *_copyFrom.m_pImpl ) )
|
|
{
|
|
}
|
|
|
|
//--------------------------------------------------------------------
|
|
DatabaseMetaData& DatabaseMetaData::operator=( const DatabaseMetaData& _copyFrom )
|
|
{
|
|
if ( this == &_copyFrom )
|
|
return *this;
|
|
|
|
m_pImpl.reset( new DatabaseMetaData_Impl( *_copyFrom.m_pImpl ) );
|
|
return *this;
|
|
}
|
|
|
|
//--------------------------------------------------------------------
|
|
DatabaseMetaData::~DatabaseMetaData()
|
|
{
|
|
}
|
|
|
|
//--------------------------------------------------------------------
|
|
bool DatabaseMetaData::isConnected() const
|
|
{
|
|
return m_pImpl->xConnection.is();
|
|
}
|
|
|
|
//--------------------------------------------------------------------
|
|
bool DatabaseMetaData::supportsSubqueriesInFrom() const
|
|
{
|
|
lcl_checkConnected( *m_pImpl );
|
|
|
|
bool supportsSubQueries = false;
|
|
try
|
|
{
|
|
sal_Int32 maxTablesInselect = m_pImpl->xConnectionMetaData->getMaxTablesInSelect();
|
|
supportsSubQueries = ( maxTablesInselect > 1 ) || ( maxTablesInselect == 0 );
|
|
// TODO: is there a better way to determine this? The above is not really true. More precise,
|
|
// it's a *very* generous heuristics ...
|
|
}
|
|
catch( const Exception& )
|
|
{
|
|
DBG_UNHANDLED_EXCEPTION();
|
|
}
|
|
return supportsSubQueries;
|
|
}
|
|
|
|
//--------------------------------------------------------------------
|
|
const ::rtl::OUString& DatabaseMetaData::getIdentifierQuoteString() const
|
|
{
|
|
return lcl_getConnectionStringSetting( *m_pImpl, m_pImpl->sCachedIdentifierQuoteString, &XDatabaseMetaData::getIdentifierQuoteString );
|
|
}
|
|
|
|
//--------------------------------------------------------------------
|
|
const ::rtl::OUString& DatabaseMetaData::getCatalogSeparator() const
|
|
{
|
|
return lcl_getConnectionStringSetting( *m_pImpl, m_pImpl->sCachedCatalogSeparator, &XDatabaseMetaData::getCatalogSeparator );
|
|
}
|
|
|
|
//--------------------------------------------------------------------
|
|
bool DatabaseMetaData::restrictIdentifiersToSQL92() const
|
|
{
|
|
lcl_checkConnected( *m_pImpl );
|
|
|
|
bool restrict( false );
|
|
Any setting;
|
|
if ( lcl_getConnectionSetting( "EnableSQL92Check", *m_pImpl, setting ) )
|
|
OSL_VERIFY( setting >>= restrict );
|
|
return restrict;
|
|
}
|
|
|
|
//--------------------------------------------------------------------
|
|
bool DatabaseMetaData::generateASBeforeCorrelationName() const
|
|
{
|
|
bool doGenerate( true );
|
|
Any setting;
|
|
if ( lcl_getConnectionSetting( "GenerateASBeforeCorrelationName", *m_pImpl, setting ) )
|
|
OSL_VERIFY( setting >>= doGenerate );
|
|
return doGenerate;
|
|
}
|
|
//--------------------------------------------------------------------
|
|
bool DatabaseMetaData::shouldEscapeDateTime() const
|
|
{
|
|
bool doGenerate( true );
|
|
Any setting;
|
|
if ( lcl_getConnectionSetting( "EscapeDateTime", *m_pImpl, setting ) )
|
|
OSL_VERIFY( setting >>= doGenerate );
|
|
return doGenerate;
|
|
}
|
|
//--------------------------------------------------------------------
|
|
bool DatabaseMetaData::isAutoIncrementPrimaryKey() const
|
|
{
|
|
bool is( true );
|
|
Any setting;
|
|
if ( lcl_getDriverSetting( "AutoIncrementIsPrimaryKey", *m_pImpl, setting ) )
|
|
OSL_VERIFY( setting >>= is );
|
|
return is;
|
|
}
|
|
//--------------------------------------------------------------------
|
|
sal_Int32 DatabaseMetaData::getBooleanComparisonMode() const
|
|
{
|
|
sal_Int32 mode( BooleanComparisonMode::EQUAL_INTEGER );
|
|
Any setting;
|
|
if ( lcl_getConnectionSetting( "BooleanComparisonMode", *m_pImpl, setting ) )
|
|
OSL_VERIFY( setting >>= mode );
|
|
return mode;
|
|
}
|
|
//--------------------------------------------------------------------
|
|
bool DatabaseMetaData::supportsRelations() const
|
|
{
|
|
lcl_checkConnected( *m_pImpl );
|
|
bool bSupport = false;
|
|
try
|
|
{
|
|
bSupport = m_pImpl->xConnectionMetaData->supportsIntegrityEnhancementFacility();
|
|
}
|
|
catch( const Exception& )
|
|
{
|
|
DBG_UNHANDLED_EXCEPTION();
|
|
}
|
|
try
|
|
{
|
|
if ( !bSupport )
|
|
{
|
|
const ::rtl::OUString url = m_pImpl->xConnectionMetaData->getURL();
|
|
char pMySQL[] = "sdbc:mysql";
|
|
bSupport = url.matchAsciiL(pMySQL,(sizeof(pMySQL)/sizeof(pMySQL[0]))-1);
|
|
}
|
|
}
|
|
catch( const Exception& )
|
|
{
|
|
DBG_UNHANDLED_EXCEPTION();
|
|
}
|
|
return bSupport;
|
|
}
|
|
|
|
//--------------------------------------------------------------------
|
|
bool DatabaseMetaData::supportsColumnAliasInOrderBy() const
|
|
{
|
|
bool doGenerate( true );
|
|
Any setting;
|
|
if ( lcl_getConnectionSetting( "ColumnAliasInOrderBy", *m_pImpl, setting ) )
|
|
OSL_VERIFY( setting >>= doGenerate );
|
|
return doGenerate;
|
|
}
|
|
|
|
//--------------------------------------------------------------------
|
|
bool DatabaseMetaData::supportsUserAdministration( const ::comphelper::ComponentContext& _rContext ) const
|
|
{
|
|
lcl_checkConnected( *m_pImpl );
|
|
|
|
bool isSupported( false );
|
|
try
|
|
{
|
|
// find the XUsersSupplier interface
|
|
// - either directly at the connection
|
|
Reference< XUsersSupplier > xUsersSupp( m_pImpl->xConnection, UNO_QUERY );
|
|
if ( !xUsersSupp.is() )
|
|
{
|
|
// - or at the driver manager
|
|
Reference< XDriverAccess > xDriverManager(
|
|
_rContext.createComponent( "com.sun.star.sdbc.DriverManager" ), UNO_QUERY_THROW );
|
|
Reference< XDataDefinitionSupplier > xDriver( xDriverManager->getDriverByURL( m_pImpl->xConnectionMetaData->getURL() ), UNO_QUERY );
|
|
if ( xDriver.is() )
|
|
xUsersSupp.set( xDriver->getDataDefinitionByConnection( m_pImpl->xConnection ), UNO_QUERY );
|
|
}
|
|
|
|
isSupported = ( xUsersSupp.is() && xUsersSupp->getUsers().is() );
|
|
}
|
|
catch( const Exception& )
|
|
{
|
|
DBG_UNHANDLED_EXCEPTION();
|
|
}
|
|
return isSupported;
|
|
}
|
|
|
|
//--------------------------------------------------------------------
|
|
bool DatabaseMetaData::displayEmptyTableFolders() const
|
|
{
|
|
bool doDisplay( true );
|
|
#ifdef IMPLEMENTED_LATER
|
|
Any setting;
|
|
if ( lcl_getConnectionSetting( "DisplayEmptyTableFolders", *m_pImpl, setting ) )
|
|
OSL_VERIFY( setting >>= doDisplay );
|
|
#else
|
|
try
|
|
{
|
|
Reference< XDatabaseMetaData > xMeta( m_pImpl->xConnectionMetaData, UNO_SET_THROW );
|
|
::rtl::OUString sConnectionURL( xMeta->getURL() );
|
|
doDisplay = sConnectionURL.compareToAscii( RTL_CONSTASCII_STRINGPARAM( "sdbc:mysql:mysqlc" ) ) == 0;
|
|
}
|
|
catch( const Exception& )
|
|
{
|
|
DBG_UNHANDLED_EXCEPTION();
|
|
}
|
|
#endif
|
|
return doDisplay;
|
|
}
|
|
//--------------------------------------------------------------------
|
|
bool DatabaseMetaData::supportsThreads() const
|
|
{
|
|
bool bSupported( true );
|
|
try
|
|
{
|
|
Reference< XDatabaseMetaData > xMeta( m_pImpl->xConnectionMetaData, UNO_SET_THROW );
|
|
::rtl::OUString sConnectionURL( xMeta->getURL() );
|
|
bSupported = sConnectionURL.compareToAscii( RTL_CONSTASCII_STRINGPARAM( "sdbc:mysql:mysqlc" ) ) != 0;
|
|
}
|
|
catch( const Exception& )
|
|
{
|
|
DBG_UNHANDLED_EXCEPTION();
|
|
}
|
|
return bSupported;
|
|
}
|
|
|
|
//........................................................................
|
|
} // namespace dbtools
|
|
//........................................................................
|
|
|