2006-07-10 08:20:08 -05:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
|
|
|
*
|
|
|
|
* $RCSfile: dbmetadata.cxx,v $
|
|
|
|
*
|
2008-01-29 01:37:49 -06:00
|
|
|
* $Revision: 1.8 $
|
2006-07-10 08:20:08 -05:00
|
|
|
*
|
2008-01-29 01:37:49 -06:00
|
|
|
* last change: $Author: vg $ $Date: 2008-01-29 08:37:49 $
|
2006-07-10 08:20:08 -05:00
|
|
|
*
|
|
|
|
* The Contents of this file are made available subject to
|
|
|
|
* the terms of GNU Lesser General Public License Version 2.1.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* GNU Lesser General Public License Version 2.1
|
|
|
|
* =============================================
|
|
|
|
* Copyright 2005 by Sun Microsystems, Inc.
|
|
|
|
* 901 San Antonio Road, Palo Alto, CA 94303, USA
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License version 2.1, as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This library 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 for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
|
|
|
* MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
|
2006-09-16 20:02:44 -05:00
|
|
|
// MARKER(update_precomp.py): autogen include statement, do not remove
|
|
|
|
#include "precompiled_connectivity.hxx"
|
|
|
|
|
2006-07-10 08:20:08 -05:00
|
|
|
#include <connectivity/dbmetadata.hxx>
|
|
|
|
#include <connectivity/dbexception.hxx>
|
|
|
|
|
|
|
|
/** === begin UNO includes === **/
|
|
|
|
#include <com/sun/star/lang/IllegalArgumentException.hpp>
|
2006-07-26 01:21:25 -05:00
|
|
|
#include <com/sun/star/container/XChild.hpp>
|
|
|
|
#include <com/sun/star/beans/XPropertySet.hpp>
|
|
|
|
#include <com/sun/star/beans/PropertyValue.hpp>
|
2006-12-13 09:13:43 -06:00
|
|
|
#include <com/sun/star/beans/XPropertySetInfo.hpp>
|
2007-11-21 07:58:59 -06:00
|
|
|
#include <com/sun/star/sdb/BooleanComparisonMode.hpp>
|
2006-12-13 09:13:43 -06:00
|
|
|
#include <com/sun/star/sdbc/XDatabaseMetaData2.hpp>
|
2006-07-10 08:20:08 -05:00
|
|
|
/** === end UNO includes === **/
|
|
|
|
|
|
|
|
#include <tools/diagnose_ex.h>
|
2006-12-13 09:13:43 -06:00
|
|
|
#include <comphelper/namedvaluecollection.hxx>
|
|
|
|
|
|
|
|
#include <boost/optional.hpp>
|
2006-07-10 08:20:08 -05:00
|
|
|
|
|
|
|
//........................................................................
|
|
|
|
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;
|
2006-12-13 09:13:43 -06:00
|
|
|
using ::com::sun::star::sdbc::XDatabaseMetaData2;
|
2006-07-10 08:20:08 -05:00
|
|
|
using ::com::sun::star::lang::IllegalArgumentException;
|
|
|
|
using ::com::sun::star::uno::Exception;
|
2006-07-26 01:21:25 -05:00
|
|
|
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;
|
2006-12-13 09:13:43 -06:00
|
|
|
using ::com::sun::star::beans::XPropertySetInfo;
|
|
|
|
using ::com::sun::star::uno::UNO_QUERY;
|
2006-07-10 08:20:08 -05:00
|
|
|
/** === end UNO using === **/
|
2007-11-21 07:58:59 -06:00
|
|
|
namespace BooleanComparisonMode = ::com::sun::star::sdb::BooleanComparisonMode;
|
2006-07-10 08:20:08 -05:00
|
|
|
|
|
|
|
//====================================================================
|
|
|
|
//= DatabaseMetaData_Impl
|
|
|
|
//====================================================================
|
|
|
|
struct DatabaseMetaData_Impl
|
|
|
|
{
|
|
|
|
Reference< XConnection > xConnection;
|
|
|
|
Reference< XDatabaseMetaData > xConnectionMetaData;
|
2006-12-13 09:13:43 -06:00
|
|
|
|
|
|
|
::boost::optional< ::rtl::OUString > sCachedIdentifierQuoteString;
|
|
|
|
::boost::optional< ::rtl::OUString > sCachedCatalogSeparator;
|
2006-07-10 08:20:08 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
namespace
|
|
|
|
{
|
2006-12-13 09:13:43 -06:00
|
|
|
//................................................................
|
2006-07-10 08:20:08 -05:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2006-12-13 09:13:43 -06:00
|
|
|
//................................................................
|
|
|
|
static void lcl_checkConnected( const DatabaseMetaData_Impl& _metaDataImpl )
|
2006-07-10 08:20:08 -05:00
|
|
|
{
|
2006-12-13 09:13:43 -06:00
|
|
|
if ( !_metaDataImpl.xConnection.is() || !_metaDataImpl.xConnectionMetaData.is() )
|
2006-07-10 08:20:08 -05:00
|
|
|
throwSQLException( "not connected", SQL_CONNECTION_DOES_NOT_EXIST, NULL );
|
|
|
|
}
|
2006-07-26 01:21:25 -05:00
|
|
|
|
2006-12-13 09:13:43 -06:00
|
|
|
//................................................................
|
2007-11-21 07:58:59 -06:00
|
|
|
static bool lcl_getConnectionSetting( const sal_Char* _asciiName, const DatabaseMetaData_Impl& _metaData, Any& _out_setting )
|
2006-07-26 01:21:25 -05:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2006-12-13 09:13:43 -06:00
|
|
|
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 );
|
2006-07-26 01:21:25 -05:00
|
|
|
|
2006-12-13 09:13:43 -06:00
|
|
|
_out_setting = xDataSourceSettings->getPropertyValue( ::rtl::OUString::createFromAscii( _asciiName ) );
|
|
|
|
}
|
|
|
|
else
|
2006-07-26 01:21:25 -05:00
|
|
|
{
|
2006-12-13 09:13:43 -06:00
|
|
|
Reference< XDatabaseMetaData2 > xExtendedMetaData( _metaData.xConnectionMetaData, UNO_QUERY_THROW );
|
|
|
|
::comphelper::NamedValueCollection aSettings( xExtendedMetaData->getConnectionInfo() );
|
|
|
|
_out_setting = aSettings.get( _asciiName );
|
|
|
|
return _out_setting.hasValue();
|
2006-07-26 01:21:25 -05:00
|
|
|
}
|
2006-12-13 09:13:43 -06:00
|
|
|
return true;
|
2006-07-26 01:21:25 -05:00
|
|
|
}
|
|
|
|
catch( const Exception& )
|
|
|
|
{
|
|
|
|
DBG_UNHANDLED_EXCEPTION();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2006-12-13 09:13:43 -06:00
|
|
|
|
|
|
|
//................................................................
|
|
|
|
static const ::rtl::OUString& lcl_getConnectionStringSetting(
|
|
|
|
const DatabaseMetaData_Impl& _metaData, ::boost::optional< ::rtl::OUString >& _cachedSetting,
|
|
|
|
::rtl::OUString (SAL_CALL XDatabaseMetaData::*_getter)() )
|
|
|
|
{
|
|
|
|
lcl_checkConnected( _metaData );
|
|
|
|
|
|
|
|
if ( !_cachedSetting )
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
_cachedSetting.reset( (_metaData.xConnectionMetaData.get()->*_getter)() );
|
|
|
|
}
|
|
|
|
catch( const Exception& ) { DBG_UNHANDLED_EXCEPTION(); }
|
|
|
|
}
|
|
|
|
return *_cachedSetting;
|
|
|
|
}
|
2006-07-10 08:20:08 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//====================================================================
|
|
|
|
//= 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();
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
2007-09-26 08:28:09 -05:00
|
|
|
bool DatabaseMetaData::supportsSubqueriesInFrom() const
|
2006-07-10 08:20:08 -05:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2006-12-13 09:13:43 -06:00
|
|
|
//--------------------------------------------------------------------
|
2007-09-26 08:28:09 -05:00
|
|
|
const ::rtl::OUString& DatabaseMetaData::getIdentifierQuoteString() const
|
2006-12-13 09:13:43 -06:00
|
|
|
{
|
|
|
|
return lcl_getConnectionStringSetting( *m_pImpl, m_pImpl->sCachedIdentifierQuoteString, &XDatabaseMetaData::getIdentifierQuoteString );
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
2007-09-26 08:28:09 -05:00
|
|
|
const ::rtl::OUString& DatabaseMetaData::getCatalogSeparator() const
|
2006-12-13 09:13:43 -06:00
|
|
|
{
|
|
|
|
return lcl_getConnectionStringSetting( *m_pImpl, m_pImpl->sCachedCatalogSeparator, &XDatabaseMetaData::getCatalogSeparator );
|
|
|
|
}
|
|
|
|
|
2006-07-26 01:21:25 -05:00
|
|
|
//--------------------------------------------------------------------
|
2007-09-26 08:28:09 -05:00
|
|
|
bool DatabaseMetaData::restrictIdentifiersToSQL92() const
|
2006-07-26 01:21:25 -05:00
|
|
|
{
|
2006-12-13 09:13:43 -06:00
|
|
|
lcl_checkConnected( *m_pImpl );
|
|
|
|
|
2006-07-26 01:21:25 -05:00
|
|
|
bool restrict( false );
|
|
|
|
Any setting;
|
2007-11-21 07:58:59 -06:00
|
|
|
if ( lcl_getConnectionSetting( "EnableSQL92Check", *m_pImpl, setting ) )
|
2006-07-26 01:21:25 -05:00
|
|
|
OSL_VERIFY( setting >>= restrict );
|
|
|
|
return restrict;
|
|
|
|
}
|
|
|
|
|
2006-12-13 09:13:43 -06:00
|
|
|
//--------------------------------------------------------------------
|
2007-09-26 08:28:09 -05:00
|
|
|
bool DatabaseMetaData::generateASBeforeCorrelationName() const
|
2006-12-13 09:13:43 -06:00
|
|
|
{
|
|
|
|
bool doGenerate( true );
|
|
|
|
Any setting;
|
2007-11-21 07:58:59 -06:00
|
|
|
if ( lcl_getConnectionSetting( "GenerateASBeforeCorrelationName", *m_pImpl, setting ) )
|
2006-12-13 09:13:43 -06:00
|
|
|
OSL_VERIFY( setting >>= doGenerate );
|
|
|
|
return doGenerate;
|
|
|
|
}
|
2008-01-29 01:37:49 -06:00
|
|
|
//--------------------------------------------------------------------
|
|
|
|
bool DatabaseMetaData::shouldEscapeDateTime() const
|
|
|
|
{
|
|
|
|
bool doGenerate( true );
|
|
|
|
Any setting;
|
|
|
|
if ( lcl_getConnectionSetting( "EscapeDateTime", *m_pImpl, setting ) )
|
|
|
|
OSL_VERIFY( setting >>= doGenerate );
|
|
|
|
return doGenerate;
|
|
|
|
}
|
2006-12-13 09:13:43 -06:00
|
|
|
|
2007-11-21 07:58:59 -06:00
|
|
|
//--------------------------------------------------------------------
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2007-09-26 08:28:09 -05:00
|
|
|
//--------------------------------------------------------------------
|
|
|
|
bool DatabaseMetaData::supportsRelations() const
|
|
|
|
{
|
|
|
|
lcl_checkConnected( *m_pImpl );
|
|
|
|
bool bSupport = false;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
bSupport = m_pImpl->xConnectionMetaData->supportsIntegrityEnhancementFacility();
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2006-07-10 08:20:08 -05:00
|
|
|
//........................................................................
|
|
|
|
} // namespace dbtools
|
|
|
|
//........................................................................
|
|
|
|
|