diff options
author | Rüdiger Timm <rt@openoffice.org> | 2007-07-06 05:47:28 +0000 |
---|---|---|
committer | Rüdiger Timm <rt@openoffice.org> | 2007-07-06 05:47:28 +0000 |
commit | 8f4ec8d39e09c8007f3d88f799afce5c5d4e506b (patch) | |
tree | d0b974c98c1e2d595f81a881cc7c56d351b625dd /connectivity/source | |
parent | 46148071f97ed9ad64b2dcdc252942a2e55cac82 (diff) |
INTEGRATION: CWS oj14 (1.57.14); FILE MERGED
2007/06/20 14:22:08 fs 1.57.14.6: getComposedRowSetStatement: partially outsourced into new class StatementComposer
2006/12/18 13:40:09 oj 1.57.14.5: RESYNC: (1.66-1.67); FILE MERGED
2006/11/07 08:46:26 oj 1.57.14.4: RESYNC: (1.60-1.66); FILE MERGED
2006/07/04 07:29:16 oj 1.57.14.3: RESYNC: (1.59-1.60); FILE MERGED
2006/03/20 11:07:38 oj 1.57.14.2: RESYNC: (1.57-1.59); FILE MERGED
2005/10/31 12:21:03 oj 1.57.14.1: findDataSource now also use XOfficeDatabaseDocument
Diffstat (limited to 'connectivity/source')
-rw-r--r-- | connectivity/source/commontools/dbtools.cxx | 163 |
1 files changed, 38 insertions, 125 deletions
diff --git a/connectivity/source/commontools/dbtools.cxx b/connectivity/source/commontools/dbtools.cxx index f552c8090a6d..16336f560b3f 100644 --- a/connectivity/source/commontools/dbtools.cxx +++ b/connectivity/source/commontools/dbtools.cxx @@ -4,9 +4,9 @@ * * $RCSfile: dbtools.cxx,v $ * - * $Revision: 1.67 $ + * $Revision: 1.68 $ * - * last change: $Author: vg $ $Date: 2006-11-21 16:59:34 $ + * last change: $Author: rt $ $Date: 2007-07-06 06:47:28 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -45,6 +45,9 @@ #ifndef _DBHELPER_DBCONVERSION_HXX_ #include <connectivity/dbconversion.hxx> #endif +#ifndef CONNECTIVITY_STATEMENTCOMPOSER_HXX +#include <connectivity/statementcomposer.hxx> +#endif #ifndef CONNECTIVITY_DIAGNOSE_EX_H #include "diagnose_ex.h" #endif @@ -95,6 +98,9 @@ #ifndef _COM_SUN_STAR_SDB_XSINGLESELECTQUERYCOMPOSER_HPP_ #include <com/sun/star/sdb/XSingleSelectQueryComposer.hpp> #endif +#ifndef _COM_SUN_STAR_SDB_XOFFICEDATABASEDOCUMENT_HPP_ +#include <com/sun/star/sdb/XOfficeDatabaseDocument.hpp> +#endif #ifndef _COM_SUN_STAR_SDB_COMMANDTYPE_HPP_ #include <com/sun/star/sdb/CommandType.hpp> #endif @@ -113,6 +119,9 @@ #ifndef _OSL_DIAGNOSE_H_ #include <osl/diagnose.h> #endif +#ifndef TOOLS_DIAGNOSE_EX_H +#include <tools/diagnose_ex.h> +#endif #ifndef _COM_SUN_STAR_UTIL_XNUMBERFORMATSSUPPLIER_HPP_ #include <com/sun/star/util/XNumberFormatsSupplier.hpp> #endif @@ -1317,7 +1326,12 @@ sal_Bool canDelete(const Reference< XPropertySet>& _rxCursorSet) // ----------------------------------------------------------------------------- Reference< XDataSource> findDataSource(const Reference< XInterface >& _xParent) { - Reference< XDataSource> xDataSource(_xParent, UNO_QUERY); + Reference< XOfficeDatabaseDocument> xDatabaseDocument(_xParent, UNO_QUERY); + Reference< XDataSource> xDataSource; + if ( xDatabaseDocument.is() ) + xDataSource = xDatabaseDocument->getDataSource(); + if ( !xDataSource.is() ) + xDataSource.set(_xParent, UNO_QUERY); if (!xDataSource.is()) { Reference< XChild> xChild(_xParent, UNO_QUERY); @@ -1326,6 +1340,7 @@ Reference< XDataSource> findDataSource(const Reference< XInterface >& _xParent) } return xDataSource; } + //------------------------------------------------------------------------------ ::rtl::OUString getComposedRowSetStatement( const Reference< XPropertySet >& _rxRowSet, const Reference< XMultiServiceFactory>& _rxFactory, sal_Bool _bUseRowSetFilter, sal_Bool _bUseRowSetOrder, Reference< XSingleSelectQueryComposer >* _pxComposer ) @@ -1340,136 +1355,34 @@ Reference< XDataSource> findDataSource(const Reference< XInterface >& _xParent) // build the statement the row set is based on (can't use the ActiveCommand property of the set // as this reflects the status after the last execute, not the currently set properties) - const ::rtl::OUString sPropCommandType = ::rtl::OUString::createFromAscii( "CommandType" ); - const ::rtl::OUString sPropFilter = ::rtl::OUString::createFromAscii( "Filter" ); - const ::rtl::OUString sPropOrder = ::rtl::OUString::createFromAscii( "Order" ); - const ::rtl::OUString sPropApplyFilter = ::rtl::OUString::createFromAscii( "ApplyFilter" ); - - const ::rtl::OUString sPropCommand = OMetaConnection::getPropMap().getNameByIndex( PROPERTY_ID_COMMAND ); - const ::rtl::OUString sPropEspaceProc = OMetaConnection::getPropMap().getNameByIndex( PROPERTY_ID_ESCAPEPROCESSING ); - sal_Int32 nCommandType = CommandType::COMMAND; ::rtl::OUString sCommand; sal_Bool bEscapeProcessing = sal_False; - _rxRowSet->getPropertyValue( sPropCommandType ) >>= nCommandType ; - _rxRowSet->getPropertyValue( sPropCommand ) >>= sCommand ; - _rxRowSet->getPropertyValue( sPropEspaceProc ) >>= bEscapeProcessing; - - switch ( nCommandType ) - { - case CommandType::COMMAND: - if ( bEscapeProcessing ) - sStatement = sCommand; - // (in case of no escape processing we assume a not parseable statement) - break; - - case CommandType::TABLE: - { - if ( !sCommand.getLength() ) - break; - - sStatement = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SELECT * FROM ")); - - ::rtl::OUString sCatalog, sSchema, sTable; - qualifiedNameComponents( xConn->getMetaData(), sCommand, sCatalog, sSchema, sTable, eInDataManipulation ); - - sStatement += composeTableNameForSelect( xConn, sCatalog, sSchema, sTable ); - } - break; - - case CommandType::QUERY: - { - // ask the connection for the query - Reference< XQueriesSupplier > xSupplyQueries( xConn, UNO_QUERY ); - Reference< XNameAccess > xQueries; - if ( xSupplyQueries.is() ) - xQueries = xQueries.query( xSupplyQueries->getQueries() ); - OSL_ENSURE( xQueries.is(), "getComposedRowSetStatement: a connection which cannot supply queries?" ); - if ( !xQueries.is() ) - break; - - if ( !xQueries->hasByName( sCommand ) ) - break; - - Reference< XPropertySet > xQuery; - xQueries->getByName( sCommand ) >>= xQuery; - OSL_ENSURE( xQuery.is(), "getComposedRowSetStatement: invalid query!" ); - if ( !xQuery.is() ) - break; - - // a native query ? - sal_Bool bQueryEscapeProcessing = sal_False; - xQuery->getPropertyValue( sPropEspaceProc ) >>= bQueryEscapeProcessing; - if ( !bQueryEscapeProcessing ) - break; - - // the command used by the query - xQuery->getPropertyValue( sPropCommand ) >>= sStatement; - if ( !sStatement.getLength() ) - break; - - // use a composer to build a statement from the query filter/order props - Reference< XMultiServiceFactory > xFactory( xConn, UNO_QUERY ); - Reference< XSingleSelectQueryComposer > xComposer; - if ( xFactory.is() ) - xComposer.set( xFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.sdb.SingleSelectQueryComposer" ) ) ), UNO_QUERY ); - if ( !xComposer.is() ) - break; - - // the "basic" statement - xComposer->setQuery( sStatement ); - - // the sort order - if ( hasProperty( sPropOrder, xQuery ) ) - xComposer->setOrder( getString( xQuery->getPropertyValue( sPropOrder ) ) ); - - // the filter - sal_Bool bApplyFilter = sal_True; - if ( hasProperty( sPropApplyFilter, xQuery ) ) - bApplyFilter = getBOOL( xQuery->getPropertyValue( sPropApplyFilter ) ); - - if ( bApplyFilter ) - xComposer->setFilter( getString( xQuery->getPropertyValue( sPropFilter ) ) ); - - // the composed statement - sStatement = xComposer->getQuery(); - } - break; + OSL_VERIFY( _rxRowSet->getPropertyValue( ::rtl::OUString::createFromAscii( "CommandType" ) ) >>= nCommandType ); + OSL_VERIFY( _rxRowSet->getPropertyValue( ::rtl::OUString::createFromAscii( "Command" ) ) >>= sCommand ); + OSL_VERIFY( _rxRowSet->getPropertyValue( ::rtl::OUString::createFromAscii( "EscapeProcessing" ) ) >>= bEscapeProcessing ); - default: - OSL_ENSURE(sal_False, "getComposedRowSetStatement: no table, no query, no statement - what else ?!"); - break; - } + StatementComposer aComposer( xConn, sCommand, nCommandType, bEscapeProcessing ); + // append sort + if ( _bUseRowSetOrder ) + aComposer.setOrder( getString( _rxRowSet->getPropertyValue( ::rtl::OUString::createFromAscii( "Order" ) ) ) ); - if ( sStatement.getLength() && ( _bUseRowSetFilter || _bUseRowSetOrder ) ) + // append filter + if ( _bUseRowSetFilter ) { - // create an composer - Reference< XMultiServiceFactory > xFactory( xConn, UNO_QUERY ); - Reference< XSingleSelectQueryComposer > xComposer; - if ( xFactory.is() ) - xComposer.set( xFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.sdb.SingleSelectQueryComposer" ) ) ), UNO_QUERY ); - if ( xComposer.is() ) - { - xComposer->setElementaryQuery( sStatement ); - - // append sort - if ( _bUseRowSetOrder ) - xComposer->setOrder( getString( _rxRowSet->getPropertyValue( sPropOrder ) ) ); + sal_Bool bApplyFilter = sal_True; + _rxRowSet->getPropertyValue( ::rtl::OUString::createFromAscii( "ApplyFilter" ) ) >>= bApplyFilter; + if ( bApplyFilter ) + aComposer.setFilter( getString( _rxRowSet->getPropertyValue( ::rtl::OUString::createFromAscii( "Filter" ) ) ) ); + } - // append filter - if ( _bUseRowSetFilter ) - { - sal_Bool bApplyFilter = sal_True; - _rxRowSet->getPropertyValue( sPropApplyFilter ) >>= bApplyFilter; - if ( bApplyFilter ) - xComposer->setFilter( getString( _rxRowSet->getPropertyValue( sPropFilter ) ) ); - } + sStatement = aComposer.getQuery(); - sStatement = xComposer->getQuery(); - if ( _pxComposer ) - *_pxComposer = xComposer; - } + if ( _pxComposer ) + { + *_pxComposer = aComposer.getComposer(); + aComposer.setDisposeComposer( false ); } } } @@ -1479,7 +1392,7 @@ Reference< XDataSource> findDataSource(const Reference< XInterface >& _xParent) } catch( const Exception& ) { - OSL_ENSURE( sal_False, "getComposedRowSetStatement: caught an (non-SQL) exception!" ); + DBG_UNHANDLED_EXCEPTION(); } return sStatement; |