office-gobmx/connectivity/source/commontools/dbmetadata.cxx
Oliver Bolte 3fd7a0199e INTEGRATION: CWS pchfix02 (1.3.32); FILE MERGED
2006/09/01 17:21:48 kaib 1.3.32.1: #i68856# Added header markers and pch files
2006-09-17 01:02:44 +00:00

219 lines
8 KiB
C++

/*************************************************************************
*
* OpenOffice.org - a multi-platform office productivity suite
*
* $RCSfile: dbmetadata.cxx,v $
*
* $Revision: 1.4 $
*
* last change: $Author: obo $ $Date: 2006-09-17 02:02:44 $
*
* 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
*
************************************************************************/
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_connectivity.hxx"
#ifndef CONNECTIVITY_INC_CONNECTIVITY_DBMETADATA_HXX
#include <connectivity/dbmetadata.hxx>
#endif
#ifndef _DBHELPER_DBEXCEPTION_HXX_
#include <connectivity/dbexception.hxx>
#endif
/** === begin UNO includes === **/
#ifndef _COM_SUN_STAR_LANG_ILLEGALARGUMENTEXCEPTION_HPP_
#include <com/sun/star/lang/IllegalArgumentException.hpp>
#endif
#ifndef _COM_SUN_STAR_CONTAINER_XCHILD_HPP_
#include <com/sun/star/container/XChild.hpp>
#endif
#ifndef _COM_SUN_STAR_BEANS_XPROPERTYSET_HPP_
#include <com/sun/star/beans/XPropertySet.hpp>
#endif
#ifndef _COM_SUN_STAR_BEANS_PROPERTYVALUE_HPP_
#include <com/sun/star/beans/PropertyValue.hpp>
#endif
/** === end UNO includes === **/
#ifndef TOOLS_DIAGNOSE_EX_H
#include <tools/diagnose_ex.h>
#endif
//........................................................................
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::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;
/** === end UNO using === **/
//====================================================================
//= DatabaseMetaData_Impl
//====================================================================
struct DatabaseMetaData_Impl
{
Reference< XConnection > xConnection;
Reference< XDatabaseMetaData > xConnectionMetaData;
};
//--------------------------------------------------------------------
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( DatabaseMetaData_Impl& _metaDataImpl )
{
if ( !_metaDataImpl.xConnection.is() )
throwSQLException( "not connected", SQL_CONNECTION_DOES_NOT_EXIST, NULL );
}
static bool lcl_getDataSourceSetting( const sal_Char* _asciiName, const DatabaseMetaData_Impl& _metaData, Any& _out_setting )
{
try
{
Reference< XChild > connectionAsChild( _metaData.xConnection, UNO_QUERY_THROW );
Reference< XPropertySet > dataSource( connectionAsChild->getParent(), UNO_QUERY_THROW );
Sequence< PropertyValue > dataSourceSettings;
OSL_VERIFY( dataSource->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Info" ) ) ) >>= dataSourceSettings );
const PropertyValue* setting( dataSourceSettings.getConstArray() );
const PropertyValue* settingEnd( setting + dataSourceSettings.getLength() );
for ( ; setting != settingEnd; ++setting )
{
if ( setting->Name.equalsAscii( _asciiName ) )
{
_out_setting = setting->Value;
return true;
}
}
}
catch( const Exception& )
{
DBG_UNHANDLED_EXCEPTION();
}
return false;
}
}
//====================================================================
//= 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 SAL_CALL 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;
}
//--------------------------------------------------------------------
bool SAL_CALL DatabaseMetaData::restrictIdentifiersToSQL92() const
{
bool restrict( false );
Any setting;
if ( lcl_getDataSourceSetting( "EnableSQL92Check", *m_pImpl, setting ) )
OSL_VERIFY( setting >>= restrict );
return restrict;
}
//........................................................................
} // namespace dbtools
//........................................................................