Tag: cws_src680_qiq
User: fs      
Date: 06/06/09 04:57:47

Modified:
 /dba/dbaccess/source/core/api/
  RowSet.cxx, RowSet.hxx

Log:
 #i51143# when executing, and an error occurs, append an info stating the 
(original) statement which lead to this error

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.143.10.2&r2=1.143.10.3
Delta lines:  +197 -145
-----------------------
--- RowSet.cxx  24 May 2006 06:40:20 -0000      1.143.10.2
+++ RowSet.cxx  9 Jun 2006 11:57:44 -0000       1.143.10.3
@@ -4,9 +4,9 @@
  *
  *  $RCSfile: RowSet.cxx,v $
  *
- *  $Revision: 1.143.10.2 $
+ *  $Revision: 1.143.10.3 $
  *
- *  last change: $Author: fs $ $Date: 2006/05/24 06:40:20 $
+ *  last change: $Author: fs $ $Date: 2006/06/09 11:57:44 $
  *
  *  The Contents of this file are made available subject to
  *  the terms of GNU Lesser General Public License Version 2.1.
@@ -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,6 +134,9 @@
 #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
@@ -202,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;
@@ -1098,14 +1104,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 );
@@ -1236,6 +1247,7 @@
        
NOTIFY_LISTERNERS_CHECK(m_aApproveListeners,XRowSetApproveListener,approveRowChange);
     if ( !bCheck )
         throwRowSetVetoException( *this, "The record operation has been 
vetoed." );
+        // TODO: resource
 }
 // -------------------------------------------------------------------------
 void ORowSet::fireRowcount()
@@ -1270,6 +1282,7 @@
        checkPositioningAllowed();
        if ( ( m_pCache->m_nPrivileges & Privilege::INSERT ) != 
Privilege::INSERT )
         throwSQLException( "No insert privileges", SQL_GENERAL_ERROR, *this );
+        // TODO: resource
 
        if ( notifyAllListenersCursorBeforeMove( aGuard ) )
        {
@@ -1336,6 +1349,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 ) )
        {
@@ -1631,77 +1645,86 @@
 }
 
 // 
-----------------------------------------------------------------------------
-// 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;
-
-       // do we need a new statement
-       if (m_bCreateStatement)
-       {
-               m_xStatement    = NULL;
-               m_xComposer             = NULL;
-               m_xAnalyzer             = NULL;
-
-               // Build the statement
-               sal_Bool bUseEscapeProcessing( sal_True );
-               Reference< XNameAccess > xTables;
-               // xTables will be filled in getCommand
-               m_aActiveCommand = getCommand(bUseEscapeProcessing,xTables);
-               if ( !m_aActiveCommand.getLength() )
-            throwSQLException( "No SQL command was provided.", 
SQL_FUNCTION_SEQUENCE_ERROR, *this );
-
+       sal_Bool bUseEscapeProcessing = impl_buildActiveCommand_throw( );
         ::rtl::OUString sCommandToExecute( m_aActiveCommand );
         if ( bUseEscapeProcessing )
-            sCommandToExecute = impl_getComposedQueryForExecution_throw();
+        sCommandToExecute = impl_getComposedQuery_throw( true );
 
+    Reference< XResultSet> xResultSet;
+    try
+    {
         m_xStatement = m_xActiveConnection->prepareStatement( 
sCommandToExecute );
-
                if ( !m_xStatement.is() )
                {
-            SQLContext aError;
+            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." ) );
-            aError.Details = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( 
"Command being prepared was:\n" ) );
-                       aError.Details += sCommandToExecute;
+                // TODO: resource
             throw aError;
                }
 
-               Reference< XPropertySet > xProp( m_xStatement, UNO_QUERY_THROW 
);
-
+               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 i = 1;
-               for(ORowVector< ORowSetValue >::const_iterator aIter = 
m_aParameterRow.begin(); aIter != m_aParameterRow.end();++aIter,++i)
+               for (   ORowVector< ORowSetValue >::const_iterator aParam = 
m_aParameterRow.begin();
+                aParam != m_aParameterRow.end();
+                ++aParam, ++i )
+               {
+                       ::dbtools::setObjectWithInfo( xParam, i, 
aParam->makeAny(), aParam->getTypeKind() );
+               }
+
+               xResultSet = m_xStatement->executeQuery();
+    }
+    catch( const SQLException& )
                {
-                       
::dbtools::setObjectWithInfo(xParam,i,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())
-                       aComposedTableName = composeTableName( 
m_xActiveConnection->getMetaData(), m_aUpdateCatalogName, m_aUpdateSchemaName, 
m_aUpdateTableName, 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;
+               m_xAnalyzer             = 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,m_aParameterRow,aComposedTableName,m_bModified,m_bNew);
+               m_pCache = new 
ORowSetCache(xResultSet,m_xAnalyzer,m_xServiceManager,m_aParameterRow,aComposedUpdateTableName,m_bModified,m_bNew);
                if ( m_nResultSetConcurrency == ResultSetConcurrency::READ_ONLY 
)
                {
                        m_nPrivileges = Privilege::SELECT;
@@ -1858,6 +1881,7 @@
                                                        
xColumn->getPropertyValue(PROPERTY_NAME) >>= sName;
                                                else
                                                        sName = 
::rtl::OUString::createFromAscii("Expression1");
+                        // TODO: resource
                                        }
                                        pColumn->setName(sName);
                                        aNames.push_back(sName);
@@ -2083,25 +2107,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:
+               {
+            Reference< XNameAccess > xTables;
+               Reference< XTablesSupplier >  xTablesAccess( 
m_xActiveConnection, UNO_QUERY );
+               if ( xTablesAccess.is() )
                {
-                       _rxRetTables = xTablesAccess->getTables();
+                       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
                        {
@@ -2110,24 +2142,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)
                                        {
@@ -2137,17 +2173,17 @@
                                        }
                                        catch(Exception&)
                                        {
-                                               OSL_ENSURE(0,"Exception 
catched!");
+                    DBG_UNHANDLED_EXCEPTION();
                                        }
 
                                        Reference<XColumnsSupplier> 
xSup(xTable,UNO_QUERY);
                                        if ( xSup.is() )
                                                m_xColumns = xSup->getColumns();
 
-                                       aQuery = 
rtl::OUString::createFromAscii("SELECT * FROM ");
+                               sCommand = 
rtl::OUString::createFromAscii("SELECT * FROM ");
                                    ::rtl::OUString sCatalog, sSchema, sTable;
                                    ::dbtools::qualifiedNameComponents( 
m_xActiveConnection->getMetaData(), m_aCommand, sCatalog, sSchema, sTable, 
::dbtools::eInDataManipulation );
-                                       aQuery += 
::dbtools::composeTableNameForSelect( m_xActiveConnection, sCatalog, sSchema, 
sTable );
+                               sCommand += 
::dbtools::composeTableNameForSelect( m_xActiveConnection, sCatalog, sSchema, 
sTable );
                                }
                                else
                                {
@@ -2155,9 +2191,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);
@@ -2167,11 +2205,11 @@
                                        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;
@@ -2194,16 +2232,25 @@
                                        }
                                }
                                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::impl_getComposedQueryForExecution_throw()
+::rtl::OUString ORowSet::impl_getComposedQuery_throw( bool _bForExecution )
 {
        m_xComposer = NULL;
     m_xAnalyzer = NULL;
@@ -2219,6 +2266,7 @@
        }
        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 );
 
@@ -2247,7 +2295,7 @@
        Reference<XColumnsSupplier> xCols( m_xComposer, UNO_QUERY_THROW );
        m_xColumns = xCols->getColumns();
 
-       return m_xComposer->getQueryWithSubstitution();
+    return _bForExecution ? m_xComposer->getQueryWithSubstitution() : 
m_xComposer->getQuery();
 }
 // 
-----------------------------------------------------------------------------
 void ORowSet::checkAndResizeParameters(sal_Int32 parameterIndex)
@@ -2482,12 +2530,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)

File [changed]: RowSet.hxx
Url: 
http://dba.openoffice.org/source/browse/dba/dbaccess/source/core/api/RowSet.hxx?r1=1.42.60.1&r2=1.42.60.2
Delta lines:  +22 -4
--------------------
--- RowSet.hxx  10 May 2006 10:54:59 -0000      1.42.60.1
+++ RowSet.hxx  9 Jun 2006 11:57:45 -0000       1.42.60.2
@@ -4,9 +4,9 @@
  *
  *  $RCSfile: RowSet.hxx,v $
  *
- *  $Revision: 1.42.60.1 $
+ *  $Revision: 1.42.60.2 $
  *
- *  last change: $Author: fs $ $Date: 2006/05/10 10:54:59 $
+ *  last change: $Author: fs $ $Date: 2006/06/09 11:57:45 $
  *
  *  The Contents of this file are made available subject to
  *  the terms of GNU Lesser General Public License Version 2.1.
@@ -176,6 +176,11 @@
 
             The query is built from our active command plus our current 
filter/order criterions.
 
+            @param _bForExecution
+                <TRUE/> if this is for executing the statement (then 
XSingleSelectQueryAnalyzer::getQueryWithSubstitution will be
+                used), or <FALSE/> if it's for presentation to the user, e.g. 
in an error message (then
+                XSingleSelectQueryAnalyzer::getQuery will be used).
+
             @precond
                 m_xActiveConnection points to a valid SDB-level connection
 
@@ -184,10 +189,23 @@
             @throws com::sun::star::uno::RuntimeException
                 if any of the components involved throws a 
com::sun::star::uno::RuntimeException
         */
-        ::rtl::OUString impl_getComposedQueryForExecution_throw();
+        ::rtl::OUString impl_getComposedQuery_throw( bool _bForExecution );
+
+        /** builds m_aActiveCommand from our settings
+
+            @return
+                whether we should use escape processing before executing the 
actual command. This is determined
+                from our own EscapeProcessing property, and possibly overruled 
by the respective property
+                of a query we're based on.
+        */
+        sal_Bool        impl_buildActiveCommand_throw();
+
+        /** prepares and executes our command
+        */
+        ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet >
+                        impl_prepareAndExecute_throw();
 
         ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection 
>  calcConnection(const ::com::sun::star::uno::Reference< 
::com::sun::star::task::XInteractionHandler >& _rxHandler) throw( 
::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException );
-               rtl::OUString getCommand(sal_Bool& 
bEscapeProcessing,::com::sun::star::uno::Reference< 
::com::sun::star::container::XNameAccess >& _rxRetTables) throw( 
::com::sun::star::sdbc::SQLException);
                // free clones and ParseTree
                void freeResources();
 




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to