User: vg      
Date: 2007/01/15 06:30:55

Modified:
   dba/dbaccess/source/core/api/statement.cxx

Log:
 INTEGRATION: CWS dba22b (1.15.56); FILE MERGED
 2006/12/13 10:39:14 fs 1.15.56.1: #i69460# statement should translate the SQL 
to SDBC level, if possible

File Changes:

Directory: /dba/dbaccess/source/core/api/
=========================================

File [changed]: statement.cxx
Url: 
http://dba.openoffice.org/source/browse/dba/dbaccess/source/core/api/statement.cxx?r1=1.15&r2=1.16
Delta lines:  +94 -65
---------------------
--- statement.cxx       17 Sep 2006 06:36:27 -0000      1.15
+++ statement.cxx       15 Jan 2007 14:30:52 -0000      1.16
@@ -65,12 +65,15 @@
 #ifndef _TOOLS_DEBUG_HXX //autogen
 #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
 
+using namespace ::com::sun::star::sdb;
 using namespace ::com::sun::star::sdbc;
-//using namespace ::com::sun::star::sdbcx;
 using namespace ::com::sun::star::beans;
 using namespace ::com::sun::star::uno;
 using namespace ::com::sun::star::lang;
@@ -189,9 +192,6 @@
                {
                        Reference< XCloseable > (m_xAggregateAsSet, 
UNO_QUERY)->close();
                }
-               catch(DisposedException& )
-               {// don't care for anymore
-               }
                catch(RuntimeException& )
                {// don't care for anymore
                }
@@ -448,57 +448,17 @@
 //************************************************************
 //  OStatement
 //************************************************************
-// com::sun::star::lang::XTypeProvider
-//--------------------------------------------------------------------------
-Sequence< Type > OStatement::getTypes() throw (RuntimeException)
-{
-       OTypeCollection aTypes(::getCppuType( (const Reference< XServiceInfo > 
*)0 ),
-                                                  ::getCppuType( (const 
Reference< XStatement > *)0 ),
-                                                       
OStatementBase::getTypes() );
-
-       return aTypes.getTypes();
-}
-
-//--------------------------------------------------------------------------
-Sequence< sal_Int8 > OStatement::getImplementationId() throw (RuntimeException)
-{
-       static OImplementationId * pId = 0;
-       if (! pId)
-       {
-               MutexGuard aGuard( Mutex::getGlobalMutex() );
-               if (! pId)
-               {
-                       static OImplementationId aId;
-                       pId = &aId;
-               }
-       }
-       return pId->getImplementationId();
-}
-
-// com::sun::star::uno::XInterface
-//--------------------------------------------------------------------------
-Any OStatement::queryInterface( const Type & rType ) throw (RuntimeException)
-{
-       Any aIface = OStatementBase::queryInterface( rType );
-       if (!aIface.hasValue())
-               aIface = ::cppu::queryInterface(
-                                       rType,
-                                       static_cast< XServiceInfo * >( this ),
-                                       static_cast< XStatement * >( this ));
-       return aIface;
-}
-
-//--------------------------------------------------------------------------
-void OStatement::acquire() throw ()
+//------------------------------------------------------------------------------
+OStatement::OStatement( const Reference< XConnection >& _xConn, const 
Reference< XInterface > & _xStatement )
+       :OStatementBase( _xConn, _xStatement )
+    ,m_bAttemptedComposerCreation( false )
 {
-       OStatementBase::acquire();
+    m_xAggregateStatement.set( _xStatement, UNO_QUERY_THROW );
 }
 
-//--------------------------------------------------------------------------
-void OStatement::release() throw ()
-{
-       OStatementBase::release();
-}
+//------------------------------------------------------------------------------
+IMPLEMENT_FORWARD_XINTERFACE2( OStatement, OStatementBase, OStatement_IFACE );
+IMPLEMENT_FORWARD_XTYPEPROVIDER2( OStatement, OStatementBase, OStatement_IFACE 
);
 
 // XServiceInfo
 
//------------------------------------------------------------------------------
@@ -516,61 +476,130 @@
 
//------------------------------------------------------------------------------
 Sequence< ::rtl::OUString > OStatement::getSupportedServiceNames(  ) throw 
(RuntimeException)
 {
-       Sequence< ::rtl::OUString > aSNS( 2 );
+       Sequence< ::rtl::OUString > aSNS( 1 );
        aSNS.getArray()[0] = SERVICE_SDBC_STATEMENT;
-       aSNS.getArray()[1] = SERVICE_SDB_STATEMENT;
        return aSNS;
 }
 
 // XStatement
 
//------------------------------------------------------------------------------
-Reference< XResultSet > OStatement::executeQuery(const rtl::OUString& sql) 
throw( SQLException, RuntimeException )
+Reference< XResultSet > OStatement::executeQuery( const rtl::OUString& _rSQL ) 
throw( SQLException, RuntimeException )
 {
        MutexGuard aGuard(m_aMutex);
        ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
 
        disposeResultSet();
-
        Reference< XResultSet > xResultSet;
-       Reference< XResultSet > xDrvResultSet = Reference< XStatement 
>(m_xAggregateAsSet, UNO_QUERY)->executeQuery(sql);
-       if (xDrvResultSet.is())
+
+    ::rtl::OUString sSQL( impl_doEscapeProcessing_nothrow( _rSQL ) );
+
+       Reference< XResultSet > xInnerResultSet = 
m_xAggregateStatement->executeQuery( sSQL );
+    Reference< XConnection > xConnection( m_xParent, UNO_QUERY_THROW );
+
+       if ( xInnerResultSet.is() )
        {
-               Reference<XDatabaseMetaData> xMeta = Reference< XConnection > 
(m_xParent, UNO_QUERY)->getMetaData();
+               Reference< XDatabaseMetaData > xMeta = 
xConnection->getMetaData();
                sal_Bool bCaseSensitive = xMeta.is() && 
xMeta->supportsMixedCaseQuotedIdentifiers();
-               xResultSet = new OResultSet(xDrvResultSet, *this, 
bCaseSensitive);
+               xResultSet = new OResultSet( xInnerResultSet, *this, 
bCaseSensitive );
 
                // keep the resultset weak
                m_aResultSet = xResultSet;
        }
+
        return xResultSet;
 }
 
 
//------------------------------------------------------------------------------
-sal_Int32 OStatement::executeUpdate(const rtl::OUString& sql) throw( 
SQLException, RuntimeException )
+sal_Int32 OStatement::executeUpdate( const rtl::OUString& _rSQL ) throw( 
SQLException, RuntimeException )
 {
        MutexGuard aGuard(m_aMutex);
        ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
 
        disposeResultSet();
 
-       return Reference< XStatement >(m_xAggregateAsSet, 
UNO_QUERY)->executeUpdate(sql);
+    ::rtl::OUString sSQL( impl_doEscapeProcessing_nothrow( _rSQL ) );
+       return m_xAggregateStatement->executeUpdate( sSQL );
 }
 
 
//------------------------------------------------------------------------------
-sal_Bool OStatement::execute(const rtl::OUString& sql) throw( SQLException, 
RuntimeException )
+sal_Bool OStatement::execute( const rtl::OUString& _rSQL ) throw( 
SQLException, RuntimeException )
 {
        MutexGuard aGuard(m_aMutex);
        ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
 
        disposeResultSet();
-       return Reference< XStatement >(m_xAggregateAsSet, 
UNO_QUERY)->execute(sql);
+
+    ::rtl::OUString sSQL( impl_doEscapeProcessing_nothrow( _rSQL ) );
+       return m_xAggregateStatement->execute( sSQL );
 }
 
 
//------------------------------------------------------------------------------
 Reference< XConnection > OStatement::getConnection(void) throw( SQLException, 
RuntimeException )
 {
-       return Reference< XConnection > (m_xParent, UNO_QUERY);
+       return Reference< XConnection >( m_xParent, UNO_QUERY );
 }
+
 // 
-----------------------------------------------------------------------------
+void SAL_CALL OStatement::disposing()
+{
+    OStatementBase::disposing();
+    m_xComposer.clear();
+    m_xAggregateStatement.clear();
+}
+
+// 
-----------------------------------------------------------------------------
+::rtl::OUString OStatement::impl_doEscapeProcessing_nothrow( const 
::rtl::OUString& _rSQL ) const
+{
+    try
+    {
+        bool bEscapeProcessing = false;
+        OSL_VERIFY( m_xAggregateAsSet->getPropertyValue( 
PROPERTY_USE_ESCAPE_PROCESSING ) >>= bEscapeProcessing );
+        if ( !bEscapeProcessing )
+            return _rSQL;
+
+        if ( !impl_ensureComposer_nothrow() )
+            return _rSQL;
+
+        bool bParseable = false;
+        try { m_xComposer->setQuery( _rSQL ); bParseable = true; }
+        catch( const SQLException& ) { }
+            
+        if ( !bParseable )
+            // if we cannot parse it, silently accept this. The driver is 
probably able to cope with it then
+            return _rSQL;
 
+        ::rtl::OUString sLowLevelSQL = m_xComposer->getQueryWithSubstitution();
+        if ( sLowLevelSQL == m_xComposer->getQuery() )
+            // if the low level SQL is the same as the high level SQL, then 
simply
+            // return the original SQL statement, without tampering with it at 
all.
+            return _rSQL;
 
+        return sLowLevelSQL;
+    }
+    catch( const Exception& )
+    {
+       DBG_UNHANDLED_EXCEPTION();
+    }
+
+    return _rSQL;
+}
+
+// 
-----------------------------------------------------------------------------
+bool OStatement::impl_ensureComposer_nothrow() const
+{
+    if ( m_bAttemptedComposerCreation )
+        return m_xComposer.is();
+
+    const_cast< OStatement* >( this )->m_bAttemptedComposerCreation = true;
+    try
+    {
+        Reference< XMultiServiceFactory > xFactory( m_xParent, UNO_QUERY_THROW 
);
+        const_cast< OStatement* >( this )->m_xComposer.set( 
xFactory->createInstance( SERVICE_NAME_SINGLESELECTQUERYCOMPOSER ), 
UNO_QUERY_THROW );
+    }
+    catch( const Exception& )
+    {
+       DBG_UNHANDLED_EXCEPTION();
+    }
+
+    return m_xComposer.is();
+}




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

Reply via email to