Tag: cws_src680_hsqlcsv User: fs Date: 2008-01-16 21:39:04+0000 Modified: dba/connectivity/source/commontools/dbtools.cxx
Log: RESYNC: (1.67-1.70); FILE MERGED File Changes: Directory: /dba/connectivity/source/commontools/ ================================================ File [changed]: dbtools.cxx Url: http://dba.openoffice.org/source/browse/dba/connectivity/source/commontools/dbtools.cxx?r1=1.62.14.3&r2=1.62.14.4 Delta lines: +123 -264 ----------------------- --- dbtools.cxx 2006-12-18 07:35:37+0000 1.62.14.3 +++ dbtools.cxx 2008-01-16 21:39:01+0000 1.62.14.4 @@ -36,155 +36,61 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_connectivity.hxx" -#ifndef _DBHELPER_DBEXCEPTION_HXX_ -#include <connectivity/dbexception.hxx> -#endif -#ifndef _CONNECTIVITY_DBTOOLS_HXX_ -#include <connectivity/dbtools.hxx> -#endif -#ifndef _DBHELPER_DBCONVERSION_HXX_ -#include <connectivity/dbconversion.hxx> -#endif -#ifndef CONNECTIVITY_DIAGNOSE_EX_H +#include "connectivity/CommonTools.hxx" #include "diagnose_ex.h" -#endif - -#ifndef _COMPHELPER_PROPERTY_HXX_ -#include <comphelper/property.hxx> -#endif -#ifndef _CONNECTIVITY_CONNCLEANUP_HXX_ -#include <connectivity/conncleanup.hxx> -#endif +#include "TConnection.hxx" -#ifndef _COM_SUN_STAR_IO_XINPUTSTREAM_HPP_ -#include <com/sun/star/io/XInputStream.hpp> -#endif -#ifndef _COM_SUN_STAR_SDBC_XROWUPDATE_HPP_ -#include <com/sun/star/sdbc/XRowUpdate.hpp> -#endif -#ifndef _COM_SUN_STAR_CONTAINER_XCHILD_HPP_ -#include <com/sun/star/container/XChild.hpp> -#endif -#ifndef _COM_SUN_STAR_SDBC_XDATASOURCE_HPP_ -#include <com/sun/star/sdbc/XDataSource.hpp> -#endif -#ifndef _COM_SUN_STAR_UNO_XNAMINGSERVICE_HPP_ -#include <com/sun/star/uno/XNamingService.hpp> -#endif -#ifndef _COM_SUN_STAR_SDBCX_XTABLESSUPPLIER_HPP_ -#include <com/sun/star/sdbcx/XTablesSupplier.hpp> -#endif -#ifndef _COM_SUN_STAR_SDBCX_XCOLUMNSSUPPLIER_HPP_ -#include <com/sun/star/sdbcx/XColumnsSupplier.hpp> -#endif -#ifndef _COM_SUN_STAR_SDBCX_PRIVILEGE_HPP_ -#include <com/sun/star/sdbcx/Privilege.hpp> -#endif -#ifndef _COM_SUN_STAR_BEANS_PROPERTYATTRIBUTE_HPP_ +/** === begin UNO includes === **/ +#include <com/sun/star/awt/XWindow.hpp> #include <com/sun/star/beans/PropertyAttribute.hpp> -#endif -#ifndef _COM_SUN_STAR_UTIL_XNUMBERFORMATTYPES_HPP_ -#include <com/sun/star/util/XNumberFormatTypes.hpp> -#endif -#ifndef _COM_SUN_STAR_UTIL_NUMBERFORMAT_HPP_ -#include <com/sun/star/util/NumberFormat.hpp> -#endif -#ifndef _COM_SUN_STAR_FORM_FORMCOMPONENTTYPE_HPP_ +#include <com/sun/star/container/XChild.hpp> #include <com/sun/star/form/FormComponentType.hpp> -#endif -#ifndef _COM_SUN_STAR_SDB_XSINGLESELECTQUERYCOMPOSER_HPP_ -#include <com/sun/star/sdb/XSingleSelectQueryComposer.hpp> -#endif -#ifndef _COM_SUN_STAR_SDB_COMMANDTYPE_HPP_ +#include <com/sun/star/io/XInputStream.hpp> +#include <com/sun/star/lang/DisposedException.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/sdb/BooleanComparisonMode.hpp> #include <com/sun/star/sdb/CommandType.hpp> -#endif -#ifndef _COM_SUN_STAR_SDBC_DATATYPE_HPP_ -#include <com/sun/star/sdbc/DataType.hpp> -#endif -#ifndef _COM_SUN_STAR_SDB_XQUERIESSUPPLIER_HPP_ +#include <com/sun/star/sdb/ParametersRequest.hpp> +#include <com/sun/star/sdb/RowSetVetoException.hpp> +#include <com/sun/star/sdb/SQLContext.hpp> +#include <com/sun/star/sdb/XCompletedConnection.hpp> +#include <com/sun/star/sdb/XInteractionSupplyParameters.hpp> +#include <com/sun/star/sdb/XOfficeDatabaseDocument.hpp> +#include <com/sun/star/sdb/XParametersSupplier.hpp> #include <com/sun/star/sdb/XQueriesSupplier.hpp> -#endif -#ifndef _COM_SUN_STAR_SDBC_XCONNECTION_HPP_ +#include <com/sun/star/sdb/XSingleSelectQueryComposer.hpp> +#include <com/sun/star/sdbc/DataType.hpp> #include <com/sun/star/sdbc/XConnection.hpp> -#endif -#ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_ -#include <com/sun/star/lang/XMultiServiceFactory.hpp> -#endif -#ifndef _OSL_DIAGNOSE_H_ -#include <osl/diagnose.h> -#endif -#ifndef _COM_SUN_STAR_UTIL_XNUMBERFORMATSSUPPLIER_HPP_ -#include <com/sun/star/util/XNumberFormatsSupplier.hpp> -#endif -#ifndef _COM_SUN_STAR_SDBC_XDRIVERMANAGER_HPP_ +#include <com/sun/star/sdbc/XDataSource.hpp> #include <com/sun/star/sdbc/XDriverManager.hpp> -#endif -#ifndef _COM_SUN_STAR_SDB_SQLCONTEXT_HPP_ -#include <com/sun/star/sdb/SQLContext.hpp> -#endif -#ifndef _COM_SUN_STAR_SDB_XCOMPLETEDCONNECTION_HPP_ -#include <com/sun/star/sdb/XCompletedConnection.hpp> -#endif -#ifndef _COM_SUN_STAR_TASK_XINTERACTIONHANDLER_HPP_ -#include <com/sun/star/task/XInteractionHandler.hpp> -#endif -#ifndef _COM_SUN_STAR_SDBC_XROWSET_HPP_ -#include <com/sun/star/sdbc/XRowSet.hpp> -#endif -#ifndef _COM_SUN_STAR_SDBC_XROW_HPP_ +#include <com/sun/star/sdbc/XParameters.hpp> #include <com/sun/star/sdbc/XRow.hpp> -#endif -#ifndef _COMPHELPER_EXTRACT_HXX_ -#include <comphelper/extract.hxx> -#endif -#ifndef _COM_SUN_STAR_AWT_XWINDOW_HPP_ -#include <com/sun/star/awt/XWindow.hpp> -#endif -#ifndef _COM_SUN_STAR_UI_DIALOGS_XEXECUTABLEDIALOG_HPP_ +#include <com/sun/star/sdbc/XRowSet.hpp> +#include <com/sun/star/sdbc/XRowUpdate.hpp> +#include <com/sun/star/sdbcx/Privilege.hpp> +#include <com/sun/star/sdbcx/XColumnsSupplier.hpp> +#include <com/sun/star/sdbcx/XTablesSupplier.hpp> +#include <com/sun/star/task/XInteractionHandler.hpp> +#include <com/sun/star/task/XInteractionRequest.hpp> #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp> -#endif -#ifndef CONNECTIVITY_CONNECTION_HXX -#include "TConnection.hxx" -#endif -#ifndef _CONNECTIVITY_COMMONTOOLS_HXX_ -#include "connectivity/CommonTools.hxx" -#endif -#ifndef _COM_SUN_STAR_LANG_DISPOSEDEXCEPTION_HPP_ -#include <com/sun/star/lang/DisposedException.hpp> -#endif -#ifndef _COM_SUN_STAR_SDB_XPARAMETERSSUPPLIER_HPP_ -#include <com/sun/star/sdb/XParametersSupplier.hpp> -#endif -#ifndef _COMPHELPER_INTERACTION_HXX_ -#include <comphelper/interaction.hxx> -#endif -#ifndef _COM_SUN_STAR_SDB_PARAMETERSREQUEST_HPP_ -#include <com/sun/star/sdb/ParametersRequest.hpp> -#endif -#ifndef _COMPHELPER_INTERACTION_HXX_ +#include <com/sun/star/uno/XNamingService.hpp> +#include <com/sun/star/util/NumberFormat.hpp> +#include <com/sun/star/util/XNumberFormatsSupplier.hpp> +#include <com/sun/star/util/XNumberFormatTypes.hpp> +/** === end UNO includes === **/ + +#include <comphelper/extract.hxx> #include <comphelper/interaction.hxx> -#endif -#ifndef _COMPHELPER_PROPERTY_HXX_ #include <comphelper/property.hxx> -#endif -#ifndef _COM_SUN_STAR_TASK_XINTERACTIONREQUEST_HPP_ -#include <com/sun/star/task/XInteractionRequest.hpp> -#endif -#ifndef _COM_SUN_STAR_TASK_XINTERACTIONHANDLER_HPP_ -#include <com/sun/star/task/XInteractionHandler.hpp> -#endif -#ifndef _COM_SUN_STAR_SDB_XINTERACTIONSUPPLYPARAMETERS_HPP_ -#include <com/sun/star/sdb/XInteractionSupplyParameters.hpp> -#endif -#ifndef _COM_SUN_STAR_SDB_ROWSETVETOEXCEPTION_HPP_ -#include <com/sun/star/sdb/RowSetVetoException.hpp> -#endif -#ifndef _COM_SUN_STAR_SDBC_XPARAMETERS_HPP_ -#include <com/sun/star/sdbc/XParameters.hpp> -#endif -#ifndef CONNECTIVITY_DIAGNOSE_EX_H -#include "diagnose_ex.h" -#endif +#include <connectivity/conncleanup.hxx> +#include <connectivity/dbconversion.hxx> +#include <connectivity/dbexception.hxx> +#include <connectivity/dbtools.hxx> +#include <connectivity/statementcomposer.hxx> +#include <osl/diagnose.h> +#include <rtl/ustrbuf.hxx> +#include <tools/diagnose_ex.h> + #include <algorithm> using namespace ::comphelper; @@ -1317,7 +1223,12 @@ // ----------------------------------------------------------------------------- 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 +1237,7 @@ } return xDataSource; } + //------------------------------------------------------------------------------ ::rtl::OUString getComposedRowSetStatement( const Reference< XPropertySet >& _rxRowSet, const Reference< XMultiServiceFactory>& _rxFactory, sal_Bool _bUseRowSetFilter, sal_Bool _bUseRowSetOrder, Reference< XSingleSelectQueryComposer >* _pxComposer ) @@ -1340,136 +1252,34 @@ // 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; - - default: - OSL_ENSURE(sal_False, "getComposedRowSetStatement: no table, no query, no statement - what else ?!"); - break; - } - - if ( sStatement.getLength() && ( _bUseRowSetFilter || _bUseRowSetOrder ) ) - { - // 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 ); + 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 ); + StatementComposer aComposer( xConn, sCommand, nCommandType, bEscapeProcessing ); // append sort if ( _bUseRowSetOrder ) - xComposer->setOrder( getString( _rxRowSet->getPropertyValue( sPropOrder ) ) ); + aComposer.setOrder( getString( _rxRowSet->getPropertyValue( ::rtl::OUString::createFromAscii( "Order" ) ) ) ); // append filter if ( _bUseRowSetFilter ) { sal_Bool bApplyFilter = sal_True; - _rxRowSet->getPropertyValue( sPropApplyFilter ) >>= bApplyFilter; + _rxRowSet->getPropertyValue( ::rtl::OUString::createFromAscii( "ApplyFilter" ) ) >>= bApplyFilter; if ( bApplyFilter ) - xComposer->setFilter( getString( _rxRowSet->getPropertyValue( sPropFilter ) ) ); + aComposer.setFilter( getString( _rxRowSet->getPropertyValue( ::rtl::OUString::createFromAscii( "Filter" ) ) ) ); } - sStatement = xComposer->getQuery(); + sStatement = aComposer.getQuery(); + if ( _pxComposer ) - *_pxComposer = xComposer; - } + { + *_pxComposer = aComposer.getComposer(); + aComposer.setDisposeComposer( false ); } } } @@ -1479,7 +1289,7 @@ } catch( const Exception& ) { - OSL_ENSURE( sal_False, "getComposedRowSetStatement: caught an (non-SQL) exception!" ); + DBG_UNHANDLED_EXCEPTION(); } return sStatement; @@ -1921,8 +1731,12 @@ _rxHandler->handle(xRequest); if (!pParams->wasSelected()) + { // canceled by the user (i.e. (s)he canceled the dialog) - throw RowSetVetoException(); + RowSetVetoException e; + e.ErrorCode = ParameterInteractionCancelled; + throw e; + } // now transfer the values from the continuation object to the parameter columns Sequence< PropertyValue > aFinalValues = pParams->getValues(); @@ -2067,6 +1881,51 @@ } } } + +// -------------------------------------------------------------------- +void getBoleanComparisonPredicate( const ::rtl::OUString& _rExpression, const sal_Bool _bValue, const sal_Int32 _nBooleanComparisonMode, + ::rtl::OUStringBuffer& _out_rSQLPredicate ) +{ + switch ( _nBooleanComparisonMode ) + { + case BooleanComparisonMode::IS_LITERAL: + _out_rSQLPredicate.append( _rExpression ); + if ( _bValue ) + _out_rSQLPredicate.appendAscii( " IS TRUE" ); + else + _out_rSQLPredicate.appendAscii( " IS FALSE" ); + break; + + case BooleanComparisonMode::EQUAL_LITERAL: + _out_rSQLPredicate.append( _rExpression ); + _out_rSQLPredicate.appendAscii( _bValue ? " = TRUE" : " = FALSE" ); + break; + + case BooleanComparisonMode::ACCESS_COMPAT: + if ( _bValue ) + { + _out_rSQLPredicate.appendAscii( " NOT ( ( " ); + _out_rSQLPredicate.append( _rExpression ); + _out_rSQLPredicate.appendAscii( " = 0 ) OR ( " ); + _out_rSQLPredicate.append( _rExpression ); + _out_rSQLPredicate.appendAscii( " IS NULL ) )" ); + } + else + { + _out_rSQLPredicate.append( _rExpression ); + _out_rSQLPredicate.appendAscii( " = 0" ); + } + break; + + case BooleanComparisonMode::EQUAL_INTEGER: + // fall through + default: + _out_rSQLPredicate.append( _rExpression ); + _out_rSQLPredicate.appendAscii( _bValue ? " = 1" : " = 0" ); + break; + } +} + //......................................................................... } // namespace dbtools //......................................................................... --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
