Tag: cws_src680_oj14
User: fs      
Date: 2007-06-05 20:16:16+0000
Modified:
   dba/dbaccess/source/core/api/RowSet.cxx
   dba/dbaccess/source/core/api/RowSet.hxx

Log:
 #i78077# implement XParametersSupplier, which allows accessing the parameters 
(before the RowSet has even been executed)

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.137.4.9&r2=1.137.4.10
Delta lines:  +89 -53
---------------------
--- RowSet.cxx  2007-06-04 20:28:00+0000        1.137.4.9
+++ RowSet.cxx  2007-06-05 20:16:13+0000        1.137.4.10
@@ -4,9 +4,9 @@
  *
  *  $RCSfile: RowSet.cxx,v $
  *
- *  $Revision: 1.137.4.9 $
+ *  $Revision: 1.137.4.10 $
  *
- *  last change: $Author: fs $ $Date: 2007/06/04 20:28:00 $
+ *  last change: $Author: fs $ $Date: 2007/06/05 20:16:13 $
  *
  *  The Contents of this file are made available subject to
  *  the terms of GNU Lesser General Public License Version 2.1.
@@ -334,7 +334,7 @@
        registerProperty(PROPERTY_URL,                                  
PROPERTY_ID_URL,                                        0,                      
                                        &m_aURL,                                
::getCppuType(reinterpret_cast< ::rtl::OUString*>(NULL)));
        registerProperty(PROPERTY_TRANSACTIONISOLATION, 
PROPERTY_ID_TRANSACTIONISOLATION,       PropertyAttribute::TRANSIENT,   
&m_nTransactionIsolation,::getCppuType(reinterpret_cast< sal_Int32*>(NULL)));
        registerMayBeVoidProperty(PROPERTY_TYPEMAP,             
PROPERTY_ID_TYPEMAP,                            
PropertyAttribute::MAYBEVOID|PropertyAttribute::TRANSIENT,      &m_aTypeMap,    
                ::getCppuType(reinterpret_cast< Reference< XNameAccess >* 
>(NULL)));
-       
registerProperty(PROPERTY_USE_ESCAPE_PROCESSING,PROPERTY_ID_USE_ESCAPE_PROCESSING,
      0,                                                              
&m_bUseEscapeProcessing,::getBooleanCppuType()  );
+       
registerProperty(PROPERTY_USE_ESCAPE_PROCESSING,PROPERTY_ID_USE_ESCAPE_PROCESSING,
      PropertyAttribute::BOUND,       
&m_bUseEscapeProcessing,::getBooleanCppuType()  );
        registerProperty(PROPERTY_QUERYTIMEOUT,                 
PROPERTY_ID_QUERYTIMEOUT,                       PropertyAttribute::TRANSIENT,   
&m_nQueryTimeOut,               ::getCppuType(reinterpret_cast< 
sal_Int32*>(NULL)));
        registerProperty(PROPERTY_MAXFIELDSIZE,                 
PROPERTY_ID_MAXFIELDSIZE,                       PropertyAttribute::TRANSIENT,   
&m_nMaxFieldSize,               ::getCppuType(reinterpret_cast< 
sal_Int32*>(NULL)));
        registerProperty(PROPERTY_MAXROWS,                              
PROPERTY_ID_MAXROWS,                            0,                              
                                &m_nMaxRows,                    
::getCppuType(reinterpret_cast< sal_Int32*>(NULL)) );
@@ -711,7 +711,7 @@
                if ( m_aOldRow.isValid() )
                        m_aOldRow->clearRow();
 
-        m_pParameters = NULL;
+        impl_disposeParametersContainer_nothrow();
        }
 }
 
@@ -1560,6 +1560,18 @@
 // -------------------------------------------------------------------------
 Reference< XIndexAccess > SAL_CALL ORowSet::getParameters(  ) throw 
(RuntimeException)
 {
+    if ( !m_pParameters.get() && m_aCommand.getLength() )
+    {
+        try
+        {
+            ::rtl::OUString sNotInterestedIn;
+            impl_initComposer_throw( sNotInterestedIn );
+        }
+        catch( const Exception& )
+        {
+               DBG_UNHANDLED_EXCEPTION();
+        }
+    }
     return m_pParameters.get();
 }
 
@@ -1655,10 +1667,8 @@
 // 
-----------------------------------------------------------------------------
 Reference< XResultSet > ORowSet::impl_prepareAndExecute_throw()
 {
-       sal_Bool bUseEscapeProcessing = impl_buildActiveCommand_throw( );
-    ::rtl::OUString sCommandToExecute( m_aActiveCommand );
-    if ( bUseEscapeProcessing )
-        sCommandToExecute = impl_getComposedQuery_throw( true );
+    ::rtl::OUString sCommandToExecute;
+    sal_Bool bUseEscapeProcessing = impl_initComposer_throw( sCommandToExecute 
);
 
     Reference< XResultSet> xResultSet;
     try
@@ -1705,7 +1715,7 @@
         // append information about what we were actually going to execute
         try
         {
-            String sQuery = bUseEscapeProcessing ? 
impl_getComposedQuery_throw( false ) : m_aActiveCommand;
+            String sQuery = bUseEscapeProcessing && m_xComposer.is() ? 
m_xComposer->getQuery() : m_aActiveCommand;
             String sInfo( DBA_RES_PARAM( RID_STR_COMMAND_LEADING_TO_ERROR, 
"$command$", sQuery ) );
             aError.append( SQLExceptionInfo::SQL_CONTEXT, sInfo );
         }
@@ -2246,6 +2256,56 @@
 }
 
 
//------------------------------------------------------------------------------
+sal_Bool ORowSet::impl_initComposer_throw( ::rtl::OUString& 
_out_rCommandToExecute )
+{
+       sal_Bool bUseEscapeProcessing = impl_buildActiveCommand_throw( );
+    _out_rCommandToExecute = m_aActiveCommand;
+    if ( !bUseEscapeProcessing )
+        return bUseEscapeProcessing;
+
+       Reference< XMultiServiceFactory > xFactory( m_xActiveConnection, 
UNO_QUERY );
+    if ( xFactory.is() )
+    {
+           try
+           {
+            ::comphelper::disposeComponent( m_xComposer );
+                   m_xComposer.set( xFactory->createInstance( 
SERVICE_NAME_SINGLESELECTQUERYCOMPOSER ), UNO_QUERY_THROW );
+           }
+           catch (const Exception& ) { m_xComposer = NULL; }
+    }
+       if ( !m_xComposer.is() )
+               m_xComposer = new OSingleSelectQueryComposer( 
impl_getTables_throw(), m_xActiveConnection, m_xServiceManager );
+
+       m_xComposer->setElementaryQuery( m_aActiveCommand );
+
+    m_xComposer->setFilter( m_bApplyFilter ? m_aFilter : ::rtl::OUString() );
+    m_xComposer->setHavingClause( m_bApplyFilter ? m_aHavingClause : 
::rtl::OUString() );
+
+    if ( m_bIgnoreResult )
+    {   // append a "0=1" filter
+        // don't simply overwrite an existent filter, this would lead to 
problems if this existent
+        // filter contains paramters (since a keyset may add parameters itself)
+        // 2003-12-12 - #23418# - [EMAIL PROTECTED]
+        m_xComposer->setElementaryQuery( m_xComposer->getQuery( ) );
+        m_xComposer->setFilter( ::rtl::OUString::createFromAscii( "0 = 1" ) );
+    }
+
+       m_xComposer->setOrder( m_aOrder );
+       m_xComposer->setGroup( m_aGroupBy );
+
+    if ( !m_xColumns.is() )
+    {
+           Reference< XColumnsSupplier > xCols( m_xComposer, UNO_QUERY_THROW );
+           m_xColumns = xCols->getColumns();
+    }
+
+    impl_initParametersContainer_nothrow();
+
+    _out_rCommandToExecute = m_xComposer->getQueryWithSubstitution();
+    return bUseEscapeProcessing;
+}
+
+//------------------------------------------------------------------------------
 sal_Bool ORowSet::impl_buildActiveCommand_throw()
 {
        // create the sql command
@@ -2354,51 +2414,11 @@
 
     return bDoEscapeProcessing;
 }
+
 
//------------------------------------------------------------------------------
-::rtl::OUString ORowSet::impl_getComposedQuery_throw( bool _bForExecution )
+void ORowSet::impl_initParametersContainer_nothrow()
 {
-       Reference< XMultiServiceFactory > xFactory( m_xActiveConnection, 
UNO_QUERY );
-    if ( xFactory.is() )
-    {
-           try
-           {
-            ::comphelper::disposeComponent( m_xComposer );
-                   m_xComposer.set( xFactory->createInstance( 
SERVICE_NAME_SINGLESELECTQUERYCOMPOSER ), UNO_QUERY_THROW );
-           }
-           catch (const Exception& ) { m_xComposer = NULL; }
-    }
-       if ( !m_xComposer.is() )
-               m_xComposer = new OSingleSelectQueryComposer( 
impl_getTables_throw(), m_xActiveConnection, m_xServiceManager );
-
-       m_xComposer->setElementaryQuery( m_aActiveCommand );
-
-       if ( m_bApplyFilter )
-       {
-               if ( m_aFilter.getLength() )
-                       m_xComposer->setFilter(m_aFilter);
-               if ( m_aHavingClause.getLength() )
-                       m_xComposer->setHavingClause(m_aHavingClause);
-       }
-
-    if ( m_bIgnoreResult )
-    {   // append a "0=1" filter
-        // don't simply overwrite an existent filter, this would lead to 
problems if this existent
-        // filter contains paramters (since a keyset may add parameters itself)
-        // 2003-12-12 - #23418# - [EMAIL PROTECTED]
-        m_xComposer->setElementaryQuery( m_xComposer->getQuery( ) );
-        m_xComposer->setFilter( ::rtl::OUString::createFromAscii( "0 = 1" ) );
-    }
-
-       if ( m_aOrder.getLength() )
-               m_xComposer->setOrder( m_aOrder );
-       if ( m_aGroupBy.getLength() )
-               m_xComposer->setGroup( m_aGroupBy );
-
-    if ( !m_xColumns.is() )
-    {
-           Reference<XColumnsSupplier> xCols( m_xComposer, UNO_QUERY_THROW );
-           m_xColumns = xCols->getColumns();
-    }
+    OSL_PRECOND( !m_pParameters.is(), 
"ORowSet::impl_initParametersContainer_nothrow: already initialized the 
parameters!" );
 
     m_pParameters = new param::ParameterWrapperContainer( m_xComposer.get() );
     // copy the premature parameters into the final ones
@@ -2407,9 +2427,25 @@
     {
         (*m_pParameters)[i] = m_aPrematureParamValues[i];
     }
+}
+
+//------------------------------------------------------------------------------
+void ORowSet::impl_disposeParametersContainer_nothrow()
+{
+    if ( !m_pParameters.is() )
+        return;
+
+    // copy the actual values to our "premature" ones, to preserve them for 
later use
+    size_t nParamCount( m_pParameters->size() );
+    m_aPrematureParamValues.resize( nParamCount );
+    for ( size_t i=0; i<nParamCount; ++i )
+    {
+        m_aPrematureParamValues[i] = (*m_pParameters)[i];
+    }
 
-    return _bForExecution ? m_xComposer->getQueryWithSubstitution() : 
m_xComposer->getQuery();
+    m_pParameters = NULL;
 }
+
 // 
-----------------------------------------------------------------------------
 ORowSetValue& ORowSet::getParameterStorage(sal_Int32 parameterIndex)
 {

File [changed]: RowSet.hxx
Url: 
http://dba.openoffice.org/source/browse/dba/dbaccess/source/core/api/RowSet.hxx?r1=1.47.22.1&r2=1.47.22.2
Delta lines:  +35 -18
---------------------
--- RowSet.hxx  2007-06-04 20:28:00+0000        1.47.22.1
+++ RowSet.hxx  2007-06-05 20:16:13+0000        1.47.22.2
@@ -4,9 +4,9 @@
  *
  *  $RCSfile: RowSet.hxx,v $
  *
- *  $Revision: 1.47.22.1 $
+ *  $Revision: 1.47.22.2 $
  *
- *  last change: $Author: fs $ $Date: 2007/06/04 20:28:00 $
+ *  last change: $Author: fs $ $Date: 2007/06/05 20:16:13 $
  *
  *  The Contents of this file are made available subject to
  *  the terms of GNU Lesser General Public License Version 2.1.
@@ -179,33 +179,42 @@
                sal_Bool                                        
m_bOwnConnection;
 
        private:
-        /** retrieves the composed SQL query to be used for preparing an SQL 
statement at the connection
+        /** builds m_aActiveCommand from our settings
 
-            The query is built from our active command plus our current 
filter/order criterions.
+            @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();
 
-            @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).
+        /** initializes our query composer, and everything which has to do 
with it
+
+            If we don't use escape processing, then we don't have a composer, 
and everything
+            related to it. Nonetheless, _out_rCommandToExecute and the return 
value are properly
+            initialized.
+
+            @param _out_rCommandToExecute
+                The command which is to be executed, according to the current 
settings -
+                it is built from our active command plus our current 
filter/order criterions.
+
+            @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.
+                Effectively, this value determines whether or not we actually 
have an composer (m_xComposer)
+                and dependent information (such as the parameters container).
 
             @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_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();
+        sal_Bool        impl_initComposer_throw( ::rtl::OUString& 
_out_rCommandToExecute );
 
         /** returns the table container of our active connection
 
@@ -457,6 +466,14 @@
             const ::com::sun::star::uno::Reference< 
::com::sun::star::beans::XPropertySet >& _rxRowSetColumn
         );
 
+        /** initializes our parameters container (m_pParameters) according to 
the parameter columns as
+            obtained from our composer
+        */
+        void    impl_initParametersContainer_nothrow();
+        /** disposes our parameters container
+        */
+        void    impl_disposeParametersContainer_nothrow();
+
     protected:
         using ORowSetBase::getFastPropertyValue;
         using ORowSetBase::firePropertyChange;




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

Reply via email to