Tag: cws_src680_qiq
User: fs      
Date: 06/05/10 03:55:02

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

Log:
 #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.143&r2=1.143.10.1
Delta lines:  +272 -290
-----------------------
--- RowSet.cxx  19 Apr 2006 13:18:18 -0000      1.143
+++ RowSet.cxx  10 May 2006 10:54:59 -0000      1.143.10.1
@@ -4,9 +4,9 @@
  *
  *  $RCSfile: RowSet.cxx,v $
  *
- *  $Revision: 1.143 $
+ *  $Revision: 1.143.10.1 $
  *
- *  last change: $Author: hr $ $Date: 2006/04/19 13:18:18 $
+ *  last change: $Author: fs $ $Date: 2006/05/10 10:54:59 $
  *
  *  The Contents of this file are made available subject to
  *  the terms of GNU Lesser General Public License Version 2.1.
@@ -134,9 +134,6 @@
 #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
@@ -1641,7 +1638,6 @@
        ::comphelper::disposeComponent(m_xOldConnection);
        m_xOldConnection = NULL;
 
-       ::rtl::OUString aSql;
        // do we need a new statement
        if (m_bCreateStatement)
        {
@@ -1650,20 +1646,31 @@
                m_xAnalyzer             = NULL;
 
                // Build the statement
-               sal_Bool bUseEscapeProcessing;
-               Reference< ::com::sun::star::container::XNameAccess > xTables;
+               sal_Bool bUseEscapeProcessing( sal_True );
+               Reference< 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);
+               if ( !m_aActiveCommand.getLength() )
+            throwSQLException( "No SQL command was provided.", 
SQL_FUNCTION_SEQUENCE_ERROR, *this );
 
-               {
-                       m_xStatement = m_xActiveConnection->prepareStatement(
-                                                                               
aSql = getComposedQuery(m_aActiveCommand, bUseEscapeProcessing,xTables));
+        ::rtl::OUString sCommandToExecute( m_aActiveCommand );
+        if ( bUseEscapeProcessing )
+            sCommandToExecute = impl_getComposedQueryForExecution_throw();
 
-                       if(m_xStatement.is())
+        m_xStatement = m_xActiveConnection->prepareStatement( 
sCommandToExecute );
+
+               if ( !m_xStatement.is() )
                        {
-                               Reference<XPropertySet> 
xProp(m_xStatement,UNO_QUERY);
+            SQLContext 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;
+            throw aError;
+               }
+
+               Reference< XPropertySet > xProp( m_xStatement, UNO_QUERY_THROW 
);
 
                 // set the result set type and concurrency
                 try
@@ -1681,7 +1688,6 @@
                                //      if(m_nFetchDirection != 
FetchDirection::FORWARD)
                                        //      
xProp->setPropertyValue(PROPERTY_FETCHDIRECTION,makeAny((sal_Int32)m_nFetchDirection));
 
-                               {
                                        Reference<XParameters> 
xParam(m_xStatement,UNO_QUERY);
                                        sal_Int32 i = 1;
                                        for(ORowVector< ORowSetValue 
>::const_iterator aIter = m_aParameterRow.begin(); aIter != 
m_aParameterRow.end();++aIter,++i)
@@ -1898,16 +1904,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);
@@ -2208,33 +2204,24 @@
        return aQuery;
 }
 
//------------------------------------------------------------------------------
-rtl::OUString ORowSet::getComposedQuery(const rtl::OUString& rQuery, sal_Bool 
bEscapeProcessing,Reference< XNameAccess >& _rxRetTables) throw( SQLException, 
RuntimeException )
+rtl::OUString ORowSet::impl_getComposedQueryForExecution_throw()
 {
-       // 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())
-               {
+       m_xComposer = NULL;
+    m_xAnalyzer = NULL;
+       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);
+               m_xComposer.set( xFactory->createInstance( 
SERVICE_NAME_SINGLESELECTQUERYCOMPOSER ), UNO_QUERY_THROW );
+               m_xAnalyzer = m_xComposer.get();
                        }
-                       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 );
+
+       m_xComposer->setElementaryQuery( m_aActiveCommand );
 
                        if ( m_bApplyFilter )
                        {
@@ -2255,18 +2242,13 @@
                 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())
-                       {
-                               Reference<XColumnsSupplier> 
xCols(m_xComposer,UNO_QUERY);
+       Reference<XColumnsSupplier> xCols( m_xComposer, UNO_QUERY_THROW );
                                m_xColumns = xCols->getColumns();
-                       }
-               }
-       }
-       return aComposedStatement;
+
+       return m_xComposer->getQueryWithSubstitution();
 }
 // 
-----------------------------------------------------------------------------
 void ORowSet::checkAndResizeParameters(sal_Int32 parameterIndex)

File [changed]: RowSet.hxx
Url: 
http://dba.openoffice.org/source/browse/dba/dbaccess/source/core/api/RowSet.hxx?r1=1.42&r2=1.42.60.1
Delta lines:  +18 -5
--------------------
--- RowSet.hxx  25 Jan 2006 15:10:07 -0000      1.42
+++ RowSet.hxx  10 May 2006 10:54:59 -0000      1.42.60.1
@@ -4,9 +4,9 @@
  *
  *  $RCSfile: RowSet.hxx,v $
  *
- *  $Revision: 1.42 $
+ *  $Revision: 1.42.60.1 $
  *
- *  last change: $Author: hr $ $Date: 2006/01/25 15:10:07 $
+ *  last change: $Author: fs $ $Date: 2006/05/10 10:54:59 $
  *
  *  The Contents of this file are made available subject to
  *  the terms of GNU Lesser General Public License Version 2.1.
@@ -172,8 +172,21 @@
                sal_Bool                                        
m_bOwnConnection;
 
        private:
+        /** retrieves the composed SQL query to be used for preparing an SQL 
statement at the connection
+
+            The query is built from our active command plus our current 
filter/order criterions.
+
+            @precond
+                m_xActiveConnection points to a valid SDB-level connection
+
+            @throws com::sun::star::sdb::SQLException
+                if an database-related error occured
+            @throws com::sun::star::uno::RuntimeException
+                if any of the components involved throws a 
com::sun::star::uno::RuntimeException
+        */
+        ::rtl::OUString impl_getComposedQueryForExecution_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 getComposedQuery(const rtl::OUString& rQuery, 
sal_Bool bEscapeProcessing,::com::sun::star::uno::Reference< 
::com::sun::star::container::XNameAccess >& _rxRetTables) 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