User: obo Date: 2006/07/10 08:03:14 Modified: dba/dbaccess/source/core/api/RowSet.cxx
Log: INTEGRATION: CWS qiq (1.143.10); FILE MERGED 2006/06/27 11:54:13 fs 1.143.10.6: RESYNC: (1.143-1.144); FILE MERGED 2006/06/16 13:35:23 fs 1.143.10.5: m_xAnalyzer is superfluous 2006/06/16 12:45:58 fs 1.143.10.4: don't overwrite m_xColumns with the composer columns, if we already have some 2006/06/09 11:57:44 fs 1.143.10.3: #i51143# when executing, and an error occurs, append an info stating the (original) statement which lead to this error 2006/05/24 06:40:20 fs 1.143.10.2: some refactoring of compose/quoteTableName and friends, in preparation of #i51143# 2006/05/10 10:54:59 fs 1.143.10.1: #i51443# allow executing queries which are based on other queries File Changes: Directory: /dba/dbaccess/source/core/api/ ========================================= File [changed]: RowSet.cxx Url: http://dba.openoffice.org/source/browse/dba/dbaccess/source/core/api/RowSet.cxx?r1=1.144&r2=1.145 Delta lines: +421 -389 ----------------------- --- RowSet.cxx 20 Jun 2006 02:35:33 -0000 1.144 +++ RowSet.cxx 10 Jul 2006 15:03:11 -0000 1.145 @@ -51,6 +51,9 @@ #ifndef _CPPUHELPER_INTERFACECONTAINER_H_ #include <cppuhelper/interfacecontainer.h> #endif +#ifndef _CPPUHELPER_EXC_HLP_HXX_ +#include <cppuhelper/exc_hlp.hxx> +#endif #ifndef _CPPUHELPER_TYPEPROVIDER_HXX_ #include <cppuhelper/typeprovider.hxx> #endif @@ -131,12 +134,12 @@ #ifndef _TOOLS_DEBUG_HXX #include <tools/debug.hxx> #endif +#ifndef TOOLS_DIAGNOSE_EX_H +#include <tools/diagnose_ex.h> +#endif #ifndef _DBHELPER_DBEXCEPTION_HXX_ #include <connectivity/dbexception.hxx> #endif -#ifndef DBACCESS_CORE_API_SINGLESELECTQUERYCOMPOSER_HXX -#include "SingleSelectQueryComposer.hxx" -#endif #ifndef _DBA_CORE_TABLECONTAINER_HXX_ #include "tablecontainer.hxx" #endif @@ -205,7 +208,7 @@ { static void throwRowSetVetoException( const Reference< XInterface >& _rSource, const sal_Char* _pAsciiMessage ) { - // TODO: localize the message + // TODO: resource (localize the message) RowSetVetoException aException; aException.Message = ::rtl::OUString::createFromAscii( _pAsciiMessage ); aException.Context = _rSource; @@ -680,7 +683,6 @@ // dispose the composer to avoid that everbody knows that the querycomposer is eol try { - m_xAnalyzer = NULL; ::comphelper::disposeComponent(m_xComposer); } catch(Exception&) @@ -1101,14 +1103,19 @@ if ( m_bBeforeFirst || m_bAfterLast ) throwSQLException( "Cannot delete the before-first or after-last row.", SQL_INVALID_CURSOR_POSITION, *this ); + // TODO: resource if ( m_bNew ) throwSQLException( "Cannot delete the insert-row.", SQL_INVALID_CURSOR_POSITION, *this ); + // TODO: resource if ( m_nResultSetConcurrency == ResultSetConcurrency::READ_ONLY ) throwSQLException( "Result set is read only.", SQL_FUNCTION_SEQUENCE_ERROR, *this ); + // TODO: resource if ( ( m_pCache->m_nPrivileges & Privilege::DELETE ) != Privilege::DELETE ) throwSQLException( "DELETE privilege not available.", SQL_FUNCTION_SEQUENCE_ERROR, *this ); + // TODO: resource if ( rowDeleted() ) throwSQLException( "Current row already deleted.", SQL_FUNCTION_SEQUENCE_ERROR, *this ); + // TODO: resource // this call position the cache indirect Any aBookmarkToDelete( m_aBookmark ); @@ -1239,6 +1246,7 @@ NOTIFY_LISTERNERS_CHECK(m_aApproveListeners,XRowSetApproveListener,approveRowChange); if ( !bCheck ) throwRowSetVetoException( *this, "The record operation has been vetoed." ); + // TODO: resource } // ------------------------------------------------------------------------- void ORowSet::fireRowcount() @@ -1273,6 +1281,7 @@ checkPositioningAllowed(); if ( ( m_pCache->m_nPrivileges & Privilege::INSERT ) != Privilege::INSERT ) throwSQLException( "No insert privileges", SQL_GENERAL_ERROR, *this ); + // TODO: resource if ( notifyAllListenersCursorBeforeMove( aGuard ) ) { @@ -1339,6 +1348,7 @@ // our current row should not be deleted anymore. So, we should not have survived the above // check "if ( !m_pCache->m_bInserted && !m_bModified )" throwSQLException( "The current row is deleted.", SQL_FUNCTION_SEQUENCE_ERROR, *this ); + // TODO: resource if ( notifyAllListenersCursorBeforeMove( aGuard ) ) { @@ -1634,68 +1644,85 @@ } // ----------------------------------------------------------------------------- -// XRowSet -void ORowSet::execute_NoApprove_NoNewConn(ResettableMutexGuard& _rClearForNotification) +Reference< XResultSet > ORowSet::impl_prepareAndExecute_throw() { - // now we can dispose our old connection - ::comphelper::disposeComponent(m_xOldConnection); - m_xOldConnection = NULL; - - ::rtl::OUString aSql; - // do we need a new statement - if (m_bCreateStatement) - { - m_xStatement = NULL; - m_xComposer = NULL; - m_xAnalyzer = NULL; - - // Build the statement - sal_Bool bUseEscapeProcessing; - Reference< ::com::sun::star::container::XNameAccess > xTables; - // xTables will be filled in getCommand - m_aActiveCommand = getCommand(bUseEscapeProcessing,xTables); - if (!m_aActiveCommand.getLength()) - throwGenericSQLException(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Empty command submitted!")),*this); + sal_Bool bUseEscapeProcessing = impl_buildActiveCommand_throw( ); + ::rtl::OUString sCommandToExecute( m_aActiveCommand ); + if ( bUseEscapeProcessing ) + sCommandToExecute = impl_getComposedQuery_throw( true ); + Reference< XResultSet> xResultSet; + try { - m_xStatement = m_xActiveConnection->prepareStatement( - aSql = getComposedQuery(m_aActiveCommand, bUseEscapeProcessing,xTables)); - - if(m_xStatement.is()) + m_xStatement = m_xActiveConnection->prepareStatement( sCommandToExecute ); + if ( !m_xStatement.is() ) { - Reference<XPropertySet> xProp(m_xStatement,UNO_QUERY); + SQLException aError; + aError.Context = *this; + aError.SQLState = getStandardSQLState( SQL_GENERAL_ERROR ); + aError.Message = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Internal error: no statement object provided by the database driver." ) ); + // TODO: resource + throw aError; + } + Reference< XPropertySet > xStatementProps( m_xStatement, UNO_QUERY_THROW ); // set the result set type and concurrency try { - xProp->setPropertyValue( PROPERTY_USEBOOKMARKS, makeAny( sal_True ) ); - setStatementResultSetType( xProp, m_nResultSetType, m_nResultSetConcurrency ); + xStatementProps->setPropertyValue( PROPERTY_USEBOOKMARKS, makeAny( sal_True ) ); + setStatementResultSetType( xStatementProps, m_nResultSetType, m_nResultSetConcurrency ); } catch(Exception&) { // this exception doesn't matter here because when we catch an exception // then the driver doesn't support this feature } - // xProp->setPropertyValue(PROPERTY_RESULTSETTYPE,makeAny(m_nResultSetType)); - // xProp->setPropertyValue(PROPERTY_RESULTSETCONCURRENCY,makeAny(m_nResultSetConcurrency)); - // if(m_nFetchDirection != FetchDirection::FORWARD) - // xProp->setPropertyValue(PROPERTY_FETCHDIRECTION,makeAny((sal_Int32)m_nFetchDirection)); - { - Reference<XParameters> xParam(m_xStatement,UNO_QUERY); + Reference< XParameters > xParam( m_xStatement, UNO_QUERY_THROW ); sal_Int32 index = 1; - for(ORowVector< ORowSetValue >::const_iterator aIter = m_aParameterRow.begin(); aIter != m_aParameterRow.end();++aIter,++index) + for ( ORowVector< ORowSetValue >::const_iterator aParam = m_aParameterRow.begin(); + aParam != m_aParameterRow.end(); + ++aParam, ++index ) + { + ::dbtools::setObjectWithInfo( xParam, index, aParam->makeAny(), aParam->getTypeKind() ); + } + + xResultSet = m_xStatement->executeQuery(); + } + catch( const SQLException& ) { - ::dbtools::setObjectWithInfo(xParam,index,aIter->makeAny(),aIter->getTypeKind()); + SQLExceptionInfo aError( ::cppu::getCaughtException() ); + OSL_ENSURE( aError.isValid(), "ORowSet::execute_NoApprove_NoNewConn: caught an SQLException which we cannot analyze!" ); + + String sInfo( DBA_RES_PARAM( RID_STR_COMMAND_LEADING_TO_ERROR, "$command$", impl_getComposedQuery_throw( false ) ) ); + aError.append( SQLExceptionInfo::SQL_CONTEXT, sInfo ); + + aError.doThrow(); } - Reference< XResultSet> xRs = m_xStatement->executeQuery(); - // create the composed table name - ::rtl::OUString aComposedTableName; - if(m_aUpdateTableName.getLength()) - composeTableName(m_xActiveConnection->getMetaData(),m_aUpdateCatalogName,m_aUpdateSchemaName,m_aUpdateTableName,aComposedTableName,sal_False,::dbtools::eInDataManipulation); + return xResultSet; +} + +// ----------------------------------------------------------------------------- +void ORowSet::execute_NoApprove_NoNewConn(ResettableMutexGuard& _rClearForNotification) +{ + // now we can dispose our old connection + ::comphelper::disposeComponent(m_xOldConnection); + m_xOldConnection = NULL; + + // do we need a new statement + if (m_bCreateStatement) + { + m_xStatement = NULL; + m_xComposer = NULL; + + Reference< XResultSet > xResultSet( impl_prepareAndExecute_throw() ); + + ::rtl::OUString aComposedUpdateTableName; + if ( m_aUpdateTableName.getLength() ) + aComposedUpdateTableName = composeTableName( m_xActiveConnection->getMetaData(), m_aUpdateCatalogName, m_aUpdateSchemaName, m_aUpdateTableName, sal_False, ::dbtools::eInDataManipulation ); - m_pCache = new ORowSetCache(xRs,m_xAnalyzer,m_xServiceManager,aComposedTableName,m_bModified,m_bNew); + m_pCache = new ORowSetCache(xResultSet,m_xComposer.get(),m_xServiceManager,aComposedUpdateTableName,m_bModified,m_bNew); if ( m_nResultSetConcurrency == ResultSetConcurrency::READ_ONLY ) { m_nPrivileges = Privilege::SELECT; @@ -1852,6 +1879,7 @@ xColumn->getPropertyValue(PROPERTY_NAME) >>= sName; else sName = ::rtl::OUString::createFromAscii("Expression1"); + // TODO: resource } pColumn->setName(sName); aNames.push_back(sName); @@ -1898,16 +1926,6 @@ aColumns,*this,m_aColumnsMutex,aNames); } } - } - else - { - ::rtl::OUString sErrorMsg(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("The command '"))); - sErrorMsg += aSql; - sErrorMsg += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("' did not succeed.")); - throwGenericSQLException(sErrorMsg,*this); - } - } - } checkCache(); // notify the rowset listeners notifyAllListeners(_rClearForNotification); @@ -2087,25 +2105,33 @@ return m_xActiveConnection; } //------------------------------------------------------------------------------ -rtl::OUString ORowSet::getCommand(sal_Bool& bEscapeProcessing,::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& _rxRetTables) throw( SQLException) +sal_Bool ORowSet::impl_buildActiveCommand_throw() { // create the sql command // from a table name or get the command out of a query (not a view) // the last use the command as it is - bEscapeProcessing = m_bUseEscapeProcessing; - rtl::OUString aQuery; - if (m_aCommand.getLength()) + sal_Bool bDoEscapeProcessing = m_bUseEscapeProcessing; + + m_aActiveCommand = ::rtl::OUString(); + ::rtl::OUString sCommand; + + if ( !m_aCommand.getLength() ) + return bDoEscapeProcessing; + + switch (m_nCommandType) { - // i always need a tables for the querycomposer - Reference< XTablesSupplier > xTablesAccess(m_xActiveConnection, UNO_QUERY); - if (xTablesAccess.is()) + case CommandType::TABLE: { - _rxRetTables = xTablesAccess->getTables(); + Reference< XNameAccess > xTables; + Reference< XTablesSupplier > xTablesAccess( m_xActiveConnection, UNO_QUERY ); + if ( xTablesAccess.is() ) + { + xTables.set( xTablesAccess->getTables(), UNO_QUERY_THROW ); } - else // the connection is no table supplier so I make it myself + else { if(!m_xActiveConnection.is()) - throw SQLException(DBACORE_RESSTRING(RID_STR_CONNECTION_INVALID),*this,SQLSTATE_GENERAL,1000,Any() ); + throw SQLException(DBA_RES(RID_STR_CONNECTION_INVALID),*this,SQLSTATE_GENERAL,1000,Any() ); sal_Bool bCase = sal_True; try { @@ -2114,24 +2140,28 @@ } catch(SQLException&) { + DBG_UNHANDLED_EXCEPTION(); } + + if ( m_pTables ) + { + m_pTables->dispose(); // clear all references + DELETEZ(m_pTables); + } + m_pTables = new OTableContainer(*this,m_aMutex,m_xActiveConnection,bCase,NULL,NULL); - _rxRetTables = m_pTables; + xTables = m_pTables; Sequence< ::rtl::OUString> aTableFilter(1); aTableFilter[0] = ::rtl::OUString::createFromAscii("%"); m_pTables->construct(aTableFilter,Sequence< ::rtl::OUString>()); } - switch (m_nCommandType) - { - case CommandType::TABLE: - { - OSL_ENSURE(_rxRetTables.is(),"ORowSet::getCommand: We got no tables from the connection!"); - if ( _rxRetTables.is() && _rxRetTables->hasByName(m_aCommand) ) + + if ( xTables->hasByName(m_aCommand) ) { Reference< XPropertySet > xTable; try { - ::cppu::extractInterface(xTable,_rxRetTables->getByName(m_aCommand)); + xTables->getByName( m_aCommand ) >>= xTable; } catch(const WrappedTargetException& e) { @@ -2141,18 +2171,17 @@ } catch(Exception&) { - OSL_ENSURE(0,"Exception catched!"); + DBG_UNHANDLED_EXCEPTION(); } Reference<XColumnsSupplier> xSup(xTable,UNO_QUERY); if ( xSup.is() ) m_xColumns = xSup->getColumns(); - sal_Bool bUseCatalogInSelect = ::dbtools::isDataSourcePropertyEnabled(m_xActiveConnection,PROPERTY_USECATALOGINSELECT,sal_True); - sal_Bool bUseSchemaInSelect = ::dbtools::isDataSourcePropertyEnabled(m_xActiveConnection,PROPERTY_USESCHEMAINSELECT,sal_True); - - aQuery = rtl::OUString::createFromAscii("SELECT * FROM "); - aQuery += ::dbtools::quoteTableName(m_xActiveConnection->getMetaData(), m_aCommand,::dbtools::eInDataManipulation,bUseCatalogInSelect,bUseSchemaInSelect); + sCommand = rtl::OUString::createFromAscii("SELECT * FROM "); + ::rtl::OUString sCatalog, sSchema, sTable; + ::dbtools::qualifiedNameComponents( m_xActiveConnection->getMetaData(), m_aCommand, sCatalog, sSchema, sTable, ::dbtools::eInDataManipulation ); + sCommand += ::dbtools::composeTableNameForSelect( m_xActiveConnection, sCatalog, sSchema, sTable ); } else { @@ -2160,9 +2189,11 @@ sError += m_aCommand; sError += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\"!")); throwGenericSQLException(sError,*this); + // TODO: resource } } break; + case CommandType::QUERY: { Reference< XQueriesSupplier > xQueriesAccess(m_xActiveConnection, UNO_QUERY); @@ -2172,18 +2203,18 @@ if (xQueries->hasByName(m_aCommand)) { Reference< XPropertySet > xQuery(xQueries->getByName(m_aCommand),UNO_QUERY); - OSL_ENSURE(xQuery.is(),"ORowSet::getCommand: Query is NULL!"); + OSL_ENSURE(xQuery.is(),"ORowSet::impl_buildActiveCommand_throw: Query is NULL!"); if ( xQuery.is() ) { - xQuery->getPropertyValue(PROPERTY_COMMAND) >>= aQuery; - bEscapeProcessing = any2bool(xQuery->getPropertyValue(PROPERTY_USE_ESCAPE_PROCESSING)); + xQuery->getPropertyValue(PROPERTY_COMMAND) >>= sCommand; + xQuery->getPropertyValue(PROPERTY_USE_ESCAPE_PROCESSING) >>= bDoEscapeProcessing; ::rtl::OUString aCatalog,aSchema,aTable; xQuery->getPropertyValue(PROPERTY_UPDATE_CATALOGNAME) >>= aCatalog; xQuery->getPropertyValue(PROPERTY_UPDATE_SCHEMANAME) >>= aSchema; xQuery->getPropertyValue(PROPERTY_UPDATE_TABLENAME) >>= aTable; if(aTable.getLength()) - composeTableName(m_xActiveConnection->getMetaData(),aCatalog,aSchema,aTable,m_aUpdateTableName,sal_False,::dbtools::eInDataManipulation); + m_aUpdateTableName = composeTableName( m_xActiveConnection->getMetaData(), aCatalog, aSchema, aTable, sal_False, ::dbtools::eInDataManipulation ); Reference<XColumnsSupplier> xSup(xQuery,UNO_QUERY); if(xSup.is()) @@ -2199,42 +2230,41 @@ } } else - throw SQLException(DBACORE_RESSTRING(RID_STR_NO_XQUERIESSUPPLIER),*this,::rtl::OUString(),0,Any()); - } break; - default: - aQuery = m_aCommand; + throw SQLException(DBA_RES(RID_STR_NO_XQUERIESSUPPLIER),*this,::rtl::OUString(),0,Any()); } + break; + + default: + sCommand = m_aCommand; + break; } - return aQuery; + + m_aActiveCommand = sCommand; + + if ( !m_aActiveCommand.getLength() ) + throwSQLException( "No SQL command was provided.", SQL_FUNCTION_SEQUENCE_ERROR, *this ); + // TODO: resource + + return bDoEscapeProcessing; } //------------------------------------------------------------------------------ -rtl::OUString ORowSet::getComposedQuery(const rtl::OUString& rQuery, sal_Bool bEscapeProcessing,Reference< XNameAccess >& _rxRetTables) throw( SQLException, RuntimeException ) +::rtl::OUString ORowSet::impl_getComposedQuery_throw( bool _bForExecution ) { - // use query composer to make a useful query with filter and/or order by part - rtl::OUString aComposedStatement = rQuery; - if (bEscapeProcessing) - { - Reference< XMultiServiceFactory > xFactory(m_xActiveConnection, UNO_QUERY); - if (xFactory.is()) - { + Reference< XMultiServiceFactory > xFactory( m_xActiveConnection, UNO_QUERY_THROW ); try { - m_xAnalyzer.set(xFactory->createInstance(SERVICE_NAME_SINGLESELECTQUERYCOMPOSER),UNO_QUERY); - m_xComposer.set(m_xAnalyzer,UNO_QUERY); + ::comphelper::disposeComponent( m_xComposer ); + m_xComposer.set( xFactory->createInstance( SERVICE_NAME_SINGLESELECTQUERYCOMPOSER ), UNO_QUERY_THROW ); } - catch (Exception&) + catch (const Exception& ) { m_xComposer = NULL; } - } - if(!m_xComposer.is()) // no composer so we create one - { - m_xAnalyzer = new OSingleSelectQueryComposer(_rxRetTables,m_xActiveConnection,m_xServiceManager); - m_xComposer.set(m_xAnalyzer,UNO_QUERY); - } - if ( m_xComposer.is() ) - { - m_xComposer->setElementaryQuery( rQuery ); + if ( !m_xComposer.is() ) + throwSQLException( "No query composer could be provided by the connection.", SQL_GENERAL_ERROR, *this ); + // TODO: resource + + m_xComposer->setElementaryQuery( m_aActiveCommand ); if ( m_bApplyFilter ) { @@ -2255,18 +2285,16 @@ m_xComposer->setFilter( ::rtl::OUString::createFromAscii( "0 = 1" ) ); } - if (m_aOrder.getLength()) - m_xComposer->setOrder(m_aOrder); + if ( m_aOrder.getLength() ) + m_xComposer->setOrder( m_aOrder ); - aComposedStatement = m_xComposer->getQuery(); - if(!m_xColumns.is()) + if ( !m_xColumns.is() ) { - Reference<XColumnsSupplier> xCols(m_xComposer,UNO_QUERY); + Reference<XColumnsSupplier> xCols( m_xComposer, UNO_QUERY_THROW ); m_xColumns = xCols->getColumns(); } - } - } - return aComposedStatement; + + return _bForExecution ? m_xComposer->getQueryWithSubstitution() : m_xComposer->getQuery(); } // ----------------------------------------------------------------------------- void ORowSet::checkAndResizeParameters(sal_Int32 parameterIndex) @@ -2500,12 +2528,16 @@ checkCache(); if ( columnIndex <= 0 ) throwSQLException( "Invalid column index", SQL_INVALID_DESCRIPTOR_INDEX, *this ); + // TODO: resource if ( rowDeleted() ) throwSQLException( "Current row is deleted", SQL_INVALID_CURSOR_POSITION, *this ); + // TODO: resource if ( m_aCurrentRow.isNull() ) throwSQLException( "Invalid cursor state", SQL_INVALID_CURSOR_STATE, *this ); + // TODO: resource if ( m_nResultSetConcurrency == ResultSetConcurrency::READ_ONLY) throwSQLException( "Result set is not writeable", SQL_GENERAL_ERROR, *this ); + // TODO: resource } // ----------------------------------------------------------------------------- void SAL_CALL ORowSet::refreshRow( ) throw(SQLException, RuntimeException) --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
