LCOV - code coverage report
Current view: top level - dbaccess/source/core/api - statement.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 146 287 50.9 %
Date: 2014-11-03 Functions: 22 45 48.9 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <statement.hxx>
      21             : #include <resultset.hxx>
      22             : #include "dbastrings.hrc"
      23             : #include <com/sun/star/lang/DisposedException.hpp>
      24             : #include <com/sun/star/sdbc/XDatabaseMetaData.hpp>
      25             : #include <comphelper/sequence.hxx>
      26             : #include <cppuhelper/supportsservice.hxx>
      27             : #include <cppuhelper/typeprovider.hxx>
      28             : #include <comphelper/property.hxx>
      29             : #include <comphelper/types.hxx>
      30             : #include <tools/debug.hxx>
      31             : #include <tools/diagnose_ex.h>
      32             : #include <connectivity/dbexception.hxx>
      33             : 
      34             : using namespace ::com::sun::star::sdb;
      35             : using namespace ::com::sun::star::sdbc;
      36             : using namespace ::com::sun::star::beans;
      37             : using namespace ::com::sun::star::uno;
      38             : using namespace ::com::sun::star::lang;
      39             : using namespace ::cppu;
      40             : using namespace ::osl;
      41             : using namespace dbaccess;
      42             : using namespace dbtools;
      43             : 
      44             : 
      45         114 : OStatementBase::OStatementBase(const Reference< XConnection > & _xConn,
      46             :                                const Reference< XInterface > & _xStatement)
      47             :     :OSubComponent(m_aMutex, _xConn)
      48             :     ,OPropertySetHelper(OComponentHelper::rBHelper)
      49             :     ,m_bUseBookmarks( false )
      50         114 :     ,m_bEscapeProcessing( true )
      51             : 
      52             : {
      53             :     OSL_ENSURE(_xStatement.is() ,"Statement is NULL!");
      54         114 :     m_xAggregateAsSet.set(_xStatement,UNO_QUERY);
      55         114 :     m_xAggregateAsCancellable = Reference< ::com::sun::star::util::XCancellable > (m_xAggregateAsSet, UNO_QUERY);
      56         114 : }
      57             : 
      58         114 : OStatementBase::~OStatementBase()
      59             : {
      60         114 : }
      61             : 
      62             : // com::sun::star::lang::XTypeProvider
      63           4 : Sequence< Type > OStatementBase::getTypes() throw (RuntimeException, std::exception)
      64             : {
      65           4 :     OTypeCollection aTypes(cppu::UnoType<XPropertySet>::get(),
      66           4 :                            cppu::UnoType<XWarningsSupplier>::get(),
      67           4 :                            cppu::UnoType<XCloseable>::get(),
      68           4 :                            cppu::UnoType<XMultipleResults>::get(),
      69           4 :                            cppu::UnoType<com::sun::star::util::XCancellable>::get(),
      70           8 :                             OSubComponent::getTypes() );
      71           8 :     Reference< XGeneratedResultSet > xGRes(m_xAggregateAsSet, UNO_QUERY);
      72           4 :     if ( xGRes.is() )
      73           4 :         aTypes = OTypeCollection(cppu::UnoType<XGeneratedResultSet>::get(),aTypes.getTypes());
      74           8 :     Reference< XPreparedBatchExecution > xPreparedBatchExecution(m_xAggregateAsSet, UNO_QUERY);
      75           4 :     if ( xPreparedBatchExecution.is() )
      76           0 :         aTypes = OTypeCollection(cppu::UnoType<XPreparedBatchExecution>::get(),aTypes.getTypes());
      77             : 
      78           8 :     return aTypes.getTypes();
      79             : }
      80             : 
      81             : // com::sun::star::uno::XInterface
      82        1116 : Any OStatementBase::queryInterface( const Type & rType ) throw (RuntimeException, std::exception)
      83             : {
      84        1116 :     Any aIface = OSubComponent::queryInterface( rType );
      85        1116 :     if (!aIface.hasValue())
      86             :     {
      87        1088 :         aIface = ::cppu::queryInterface(
      88             :                     rType,
      89             :                     static_cast< XPropertySet * >( this ),
      90             :                     static_cast< XWarningsSupplier * >( this ),
      91             :                     static_cast< XCloseable * >( this ),
      92             :                     static_cast< XMultipleResults * >( this ),
      93         544 :                     static_cast< ::com::sun::star::util::XCancellable * >( this ));
      94         544 :         if ( !aIface.hasValue() )
      95             :         {
      96         366 :             Reference< XGeneratedResultSet > xGRes(m_xAggregateAsSet, UNO_QUERY);
      97         366 :             if ( cppu::UnoType<XGeneratedResultSet>::get()== rType && xGRes.is() )
      98           0 :                 aIface = ::cppu::queryInterface(rType,static_cast< XGeneratedResultSet * >( this ));
      99             :         }
     100         544 :         if ( !aIface.hasValue() )
     101             :         {
     102         366 :             Reference< XPreparedBatchExecution > xGRes(m_xAggregateAsSet, UNO_QUERY);
     103         366 :             if ( cppu::UnoType<XPreparedBatchExecution>::get()== rType && xGRes.is() )
     104           0 :                 aIface = ::cppu::queryInterface(rType,static_cast< XPreparedBatchExecution * >( this ));
     105             :         }
     106             :     }
     107        1116 :     return aIface;
     108             : }
     109             : 
     110        3962 : void OStatementBase::acquire() throw ()
     111             : {
     112        3962 :     OSubComponent::acquire();
     113        3962 : }
     114             : 
     115        3874 : void OStatementBase::release() throw ()
     116             : {
     117        3874 :     OSubComponent::release();
     118        3874 : }
     119             : 
     120         190 : void OStatementBase::disposeResultSet()
     121             : {
     122             :     // free the cursor if alive
     123         190 :     Reference< XComponent > xComp(m_aResultSet.get(), UNO_QUERY);
     124         190 :     if (xComp.is())
     125          10 :         xComp->dispose();
     126         190 :     m_aResultSet = NULL;
     127         190 : }
     128             : 
     129             : // OComponentHelper
     130         114 : void OStatementBase::disposing()
     131             : {
     132         114 :     OPropertySetHelper::disposing();
     133             : 
     134         114 :     MutexGuard aGuard(m_aMutex);
     135             : 
     136             :     // free pending results
     137         114 :     disposeResultSet();
     138             : 
     139             :     // free the original statement
     140             :     {
     141         114 :         MutexGuard aCancelGuard(m_aCancelMutex);
     142         114 :         m_xAggregateAsCancellable = NULL;
     143             :     }
     144             : 
     145         114 :     if ( m_xAggregateAsSet.is() )
     146             :     {
     147             :         try
     148             :         {
     149         114 :             Reference< XCloseable > (m_xAggregateAsSet, UNO_QUERY)->close();
     150             :         }
     151           0 :         catch(RuntimeException& )
     152             :         {// don't care for anymore
     153             :         }
     154             :     }
     155         114 :     m_xAggregateAsSet = NULL;
     156             : 
     157             :     // free the parent at last
     158         114 :     OSubComponent::disposing();
     159         114 : }
     160             : 
     161             : // XCloseable
     162           0 : void OStatementBase::close(void) throw( SQLException, RuntimeException, std::exception )
     163             : {
     164             :     {
     165           0 :         MutexGuard aGuard( m_aMutex );
     166           0 :         ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
     167             :     }
     168           0 :     dispose();
     169           0 : }
     170             : 
     171             : // OPropertySetHelper
     172           2 : Reference< XPropertySetInfo > OStatementBase::getPropertySetInfo() throw (RuntimeException, std::exception)
     173             : {
     174           2 :     return createPropertySetInfo( getInfoHelper() ) ;
     175             : }
     176             : 
     177             : // comphelper::OPropertyArrayUsageHelper
     178          64 : ::cppu::IPropertyArrayHelper* OStatementBase::createArrayHelper( ) const
     179             : {
     180          64 :     BEGIN_PROPERTY_HELPER(10)
     181          64 :         DECL_PROP0(CURSORNAME,              OUString);
     182          64 :         DECL_PROP0_BOOL(ESCAPE_PROCESSING);
     183          64 :         DECL_PROP0(FETCHDIRECTION,          sal_Int32);
     184          64 :         DECL_PROP0(FETCHSIZE,               sal_Int32);
     185          64 :         DECL_PROP0(MAXFIELDSIZE,            sal_Int32);
     186          64 :         DECL_PROP0(MAXROWS,                 sal_Int32);
     187          64 :         DECL_PROP0(QUERYTIMEOUT,            sal_Int32);
     188          64 :         DECL_PROP0(RESULTSETCONCURRENCY,    sal_Int32);
     189          64 :         DECL_PROP0(RESULTSETTYPE,           sal_Int32);
     190          64 :         DECL_PROP0_BOOL(USEBOOKMARKS);
     191          64 :     END_PROPERTY_HELPER();
     192             : }
     193             : 
     194             : // cppu::OPropertySetHelper
     195         628 : ::cppu::IPropertyArrayHelper& OStatementBase::getInfoHelper()
     196             : {
     197         628 :     return *getArrayHelper();
     198             : }
     199             : 
     200         182 : sal_Bool OStatementBase::convertFastPropertyValue( Any & rConvertedValue, Any & rOldValue, sal_Int32 nHandle, const Any& rValue ) throw( IllegalArgumentException  )
     201             : {
     202         182 :     bool bModified(false);
     203         182 :     switch (nHandle)
     204             :     {
     205             :         case PROPERTY_ID_USEBOOKMARKS:
     206          40 :             bModified = ::comphelper::tryPropertyValue( rConvertedValue, rOldValue, rValue, m_bUseBookmarks );
     207          40 :             break;
     208             : 
     209             :         case PROPERTY_ID_ESCAPE_PROCESSING:
     210          22 :             bModified = ::comphelper::tryPropertyValue( rConvertedValue, rOldValue, rValue, m_bEscapeProcessing );
     211          22 :             break;
     212             : 
     213             :         default:
     214         120 :             if ( m_xAggregateAsSet.is() )
     215             :             {
     216             :                 // get the property name
     217         120 :                 OUString sPropName;
     218         120 :                 getInfoHelper().fillPropertyMembersByHandle( &sPropName, NULL, nHandle );
     219             : 
     220             :                 // now set the value
     221         240 :                 Any aCurrentValue = m_xAggregateAsSet->getPropertyValue( sPropName );
     222         120 :                 if ( aCurrentValue != rValue )
     223             :                 {
     224          40 :                     rOldValue = aCurrentValue;
     225          40 :                     rConvertedValue = rValue;
     226          40 :                     bModified = true;
     227         120 :                 }
     228             :             }
     229         120 :             break;
     230             :     }
     231         182 :     return bModified;
     232             : }
     233             : 
     234         102 : void OStatementBase::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const Any& rValue ) throw (Exception, std::exception)
     235             : {
     236         102 :     switch ( nHandle )
     237             :     {
     238             :         case PROPERTY_ID_USEBOOKMARKS:
     239             :         {
     240          40 :             m_bUseBookmarks = ::comphelper::getBOOL( rValue );
     241          40 :             if ( m_xAggregateAsSet.is() && m_xAggregateAsSet->getPropertySetInfo()->hasPropertyByName( PROPERTY_USEBOOKMARKS ) )
     242           0 :                 m_xAggregateAsSet->setPropertyValue( PROPERTY_USEBOOKMARKS, rValue );
     243             :         }
     244          40 :         break;
     245             : 
     246             :         case PROPERTY_ID_ESCAPE_PROCESSING:
     247          22 :             m_bEscapeProcessing = ::comphelper::getBOOL( rValue );
     248          22 :             if ( m_xAggregateAsSet.is() )
     249          22 :                 m_xAggregateAsSet->setPropertyValue( PROPERTY_ESCAPE_PROCESSING, rValue );
     250          22 :             break;
     251             : 
     252             :         default:
     253          40 :             if ( m_xAggregateAsSet.is() )
     254             :             {
     255          40 :                 OUString sPropName;
     256          40 :                 getInfoHelper().fillPropertyMembersByHandle( &sPropName, NULL, nHandle );
     257          40 :                 m_xAggregateAsSet->setPropertyValue( sPropName, rValue );
     258             :             }
     259          40 :             break;
     260             :     }
     261         102 : }
     262             : 
     263           0 : void OStatementBase::getFastPropertyValue( Any& rValue, sal_Int32 nHandle ) const
     264             : {
     265           0 :     switch (nHandle)
     266             :     {
     267             :         case PROPERTY_ID_USEBOOKMARKS:
     268           0 :             rValue <<= m_bUseBookmarks;
     269           0 :             break;
     270             : 
     271             :         case PROPERTY_ID_ESCAPE_PROCESSING:
     272             :             // don't rely on our aggregate - if it implements this wrong, and always returns
     273             :             // TRUE here, then we would loop in impl_doEscapeProcessing_nothrow
     274           0 :             rValue <<= m_bEscapeProcessing;
     275           0 :             break;
     276             : 
     277             :         default:
     278           0 :             if ( m_xAggregateAsSet.is() )
     279             :             {
     280           0 :                 OUString sPropName;
     281           0 :                 const_cast< OStatementBase* >( this )->getInfoHelper().fillPropertyMembersByHandle( &sPropName, NULL, nHandle );
     282           0 :                 rValue = m_xAggregateAsSet->getPropertyValue( sPropName );
     283             :             }
     284           0 :             break;
     285             :     }
     286           0 : }
     287             : 
     288             : // XWarningsSupplier
     289           0 : Any OStatementBase::getWarnings(void) throw( SQLException, RuntimeException, std::exception )
     290             : {
     291           0 :     MutexGuard aGuard(m_aMutex);
     292           0 :     ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
     293             : 
     294           0 :     return Reference< XWarningsSupplier >(m_xAggregateAsSet, UNO_QUERY)->getWarnings();
     295             : }
     296             : 
     297           0 : void OStatementBase::clearWarnings(void) throw( SQLException, RuntimeException, std::exception )
     298             : {
     299           0 :     MutexGuard aGuard(m_aMutex);
     300           0 :     ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
     301             : 
     302           0 :     Reference< XWarningsSupplier >(m_xAggregateAsSet, UNO_QUERY)->clearWarnings();
     303           0 : }
     304             : 
     305             : // ::com::sun::star::util::XCancellable
     306           0 : void OStatementBase::cancel(void) throw( RuntimeException, std::exception )
     307             : {
     308             :     // no blocking as cancel is typically called from a different thread
     309           0 :     ClearableMutexGuard aCancelGuard(m_aCancelMutex);
     310           0 :     if (m_xAggregateAsCancellable.is())
     311           0 :         m_xAggregateAsCancellable->cancel();
     312             :     // else do nothing
     313           0 : }
     314             : 
     315             : // XMultipleResults
     316           0 : Reference< XResultSet > SAL_CALL OStatementBase::getResultSet(  ) throw(SQLException, RuntimeException, std::exception)
     317             : {
     318           0 :     MutexGuard aGuard(m_aMutex);
     319           0 :     ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
     320             : 
     321             :     // first check the meta data
     322           0 :     Reference<XDatabaseMetaData> xMeta = Reference< XConnection > (m_xParent, UNO_QUERY)->getMetaData();
     323           0 :     if (!xMeta.is() && !xMeta->supportsMultipleResultSets())
     324           0 :         throwFunctionSequenceException(*this);
     325             : 
     326           0 :     return Reference< XMultipleResults >(m_xAggregateAsSet, UNO_QUERY)->getResultSet();
     327             : }
     328             : 
     329           0 : sal_Int32 SAL_CALL OStatementBase::getUpdateCount(  ) throw(SQLException, RuntimeException, std::exception)
     330             : {
     331           0 :     MutexGuard aGuard(m_aMutex);
     332           0 :     ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
     333             : 
     334             :     // first check the meta data
     335           0 :     Reference<XDatabaseMetaData> xMeta = Reference< XConnection > (m_xParent, UNO_QUERY)->getMetaData();
     336           0 :     if (!xMeta.is() && !xMeta->supportsMultipleResultSets())
     337           0 :         throwFunctionSequenceException(*this);
     338             : 
     339           0 :     return Reference< XMultipleResults >(m_xAggregateAsSet, UNO_QUERY)->getUpdateCount();
     340             : }
     341             : 
     342           0 : sal_Bool SAL_CALL OStatementBase::getMoreResults(  ) throw(SQLException, RuntimeException, std::exception)
     343             : {
     344           0 :     MutexGuard aGuard(m_aMutex);
     345           0 :     ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
     346             : 
     347             :     // first check the meta data
     348           0 :     Reference<XDatabaseMetaData> xMeta = Reference< XConnection > (m_xParent, UNO_QUERY)->getMetaData();
     349           0 :     if (!xMeta.is() && !xMeta->supportsMultipleResultSets())
     350           0 :         throwFunctionSequenceException(*this);
     351             : 
     352             :     // free the previous results
     353           0 :     disposeResultSet();
     354             : 
     355           0 :     return Reference< XMultipleResults >(m_xAggregateAsSet, UNO_QUERY)->getMoreResults();
     356             : }
     357             : 
     358             : // XPreparedBatchExecution
     359           0 : void SAL_CALL OStatementBase::addBatch(  ) throw(SQLException, RuntimeException, std::exception)
     360             : {
     361           0 :     MutexGuard aGuard(m_aMutex);
     362           0 :     ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
     363             : 
     364             :     // first check the meta data
     365           0 :     Reference<XDatabaseMetaData> xMeta = Reference< XConnection > (m_xParent, UNO_QUERY)->getMetaData();
     366           0 :     if (!xMeta.is() && !xMeta->supportsBatchUpdates())
     367           0 :         throwFunctionSequenceException(*this);
     368             : 
     369           0 :     Reference< XPreparedBatchExecution >(m_xAggregateAsSet, UNO_QUERY)->addBatch();
     370           0 : }
     371             : 
     372           0 : void SAL_CALL OStatementBase::clearBatch(  ) throw(SQLException, RuntimeException, std::exception)
     373             : {
     374           0 :     MutexGuard aGuard(m_aMutex);
     375           0 :     ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
     376             : 
     377             :     // first check the meta data
     378           0 :     Reference<XDatabaseMetaData> xMeta = Reference< XConnection > (m_xParent, UNO_QUERY)->getMetaData();
     379           0 :     if (!xMeta.is() && !xMeta->supportsBatchUpdates())
     380           0 :         throwFunctionSequenceException(*this);
     381             : 
     382           0 :     Reference< XPreparedBatchExecution >(m_xAggregateAsSet, UNO_QUERY)->clearBatch();
     383           0 : }
     384             : 
     385           0 : Sequence< sal_Int32 > SAL_CALL OStatementBase::executeBatch(  ) throw(SQLException, RuntimeException, std::exception)
     386             : {
     387           0 :     MutexGuard aGuard(m_aMutex);
     388           0 :     ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
     389             : 
     390             :     // first check the meta data
     391           0 :     Reference<XDatabaseMetaData> xMeta = Reference< XConnection > (m_xParent, UNO_QUERY)->getMetaData();
     392           0 :     if (!xMeta.is() && !xMeta->supportsBatchUpdates())
     393           0 :         throwFunctionSequenceException(*this);
     394             : 
     395             :     // free the previous results
     396           0 :     disposeResultSet();
     397             : 
     398           0 :     return Reference< XPreparedBatchExecution >(m_xAggregateAsSet, UNO_QUERY)->executeBatch();
     399             : }
     400             : 
     401           0 : Reference< XResultSet > SAL_CALL OStatementBase::getGeneratedValues(  ) throw (SQLException, RuntimeException, std::exception)
     402             : {
     403           0 :     MutexGuard aGuard(m_aMutex);
     404           0 :     ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
     405           0 :     Reference< XGeneratedResultSet > xGRes(m_xAggregateAsSet, UNO_QUERY);
     406             : 
     407           0 :     if ( xGRes.is() )
     408           0 :         return xGRes->getGeneratedValues(  );
     409           0 :     return Reference< XResultSet >();
     410             : }
     411             : 
     412             : 
     413             : //  OStatement
     414             : 
     415          26 : OStatement::OStatement( const Reference< XConnection >& _xConn, const Reference< XInterface > & _xStatement )
     416             :     :OStatementBase( _xConn, _xStatement )
     417          26 :     ,m_bAttemptedComposerCreation( false )
     418             : {
     419          26 :     m_xAggregateStatement.set( _xStatement, UNO_QUERY_THROW );
     420          26 : }
     421             : 
     422        1702 : IMPLEMENT_FORWARD_XINTERFACE2( OStatement, OStatementBase, OStatement_IFACE );
     423           4 : IMPLEMENT_FORWARD_XTYPEPROVIDER2( OStatement, OStatementBase, OStatement_IFACE );
     424             : 
     425             : // XServiceInfo
     426           0 : OUString OStatement::getImplementationName(  ) throw(RuntimeException, std::exception)
     427             : {
     428           0 :     return OUString("com.sun.star.sdb.OStatement");
     429             : }
     430             : 
     431           0 : sal_Bool OStatement::supportsService( const OUString& _rServiceName ) throw (RuntimeException, std::exception)
     432             : {
     433           0 :     return cppu::supportsService(this, _rServiceName);
     434             : }
     435             : 
     436           0 : Sequence< OUString > OStatement::getSupportedServiceNames(  ) throw (RuntimeException, std::exception)
     437             : {
     438           0 :     Sequence< OUString > aSNS( 1 );
     439           0 :     aSNS.getArray()[0] = SERVICE_SDBC_STATEMENT;
     440           0 :     return aSNS;
     441             : }
     442             : 
     443             : // XStatement
     444          30 : Reference< XResultSet > OStatement::executeQuery( const OUString& _rSQL ) throw( SQLException, RuntimeException, std::exception )
     445             : {
     446          30 :     MutexGuard aGuard(m_aMutex);
     447          30 :     ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
     448             : 
     449          30 :     disposeResultSet();
     450          30 :     Reference< XResultSet > xResultSet;
     451             : 
     452          60 :     OUString sSQL( impl_doEscapeProcessing_nothrow( _rSQL ) );
     453             : 
     454          38 :     Reference< XResultSet > xInnerResultSet = m_xAggregateStatement->executeQuery( sSQL );
     455          16 :     Reference< XConnection > xConnection( m_xParent, UNO_QUERY_THROW );
     456             : 
     457           8 :     if ( xInnerResultSet.is() )
     458             :     {
     459           8 :         Reference< XDatabaseMetaData > xMeta = xConnection->getMetaData();
     460           8 :         bool bCaseSensitive = xMeta.is() && xMeta->supportsMixedCaseQuotedIdentifiers();
     461           8 :         xResultSet = new OResultSet( xInnerResultSet, *this, bCaseSensitive );
     462             : 
     463             :         // keep the resultset weak
     464           8 :         m_aResultSet = xResultSet;
     465             :     }
     466             : 
     467          38 :     return xResultSet;
     468             : }
     469             : 
     470           0 : sal_Int32 OStatement::executeUpdate( const OUString& _rSQL ) throw( SQLException, RuntimeException, std::exception )
     471             : {
     472           0 :     MutexGuard aGuard(m_aMutex);
     473           0 :     ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
     474             : 
     475           0 :     disposeResultSet();
     476             : 
     477           0 :     OUString sSQL( impl_doEscapeProcessing_nothrow( _rSQL ) );
     478           0 :     return m_xAggregateStatement->executeUpdate( sSQL );
     479             : }
     480             : 
     481           0 : sal_Bool OStatement::execute( const OUString& _rSQL ) throw( SQLException, RuntimeException, std::exception )
     482             : {
     483           0 :     MutexGuard aGuard(m_aMutex);
     484           0 :     ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
     485             : 
     486           0 :     disposeResultSet();
     487             : 
     488           0 :     OUString sSQL( impl_doEscapeProcessing_nothrow( _rSQL ) );
     489           0 :     return m_xAggregateStatement->execute( sSQL );
     490             : }
     491             : 
     492           0 : void OStatement::addBatch( const OUString& _rSQL ) throw( SQLException, RuntimeException, std::exception )
     493             : {
     494           0 :     MutexGuard aGuard(m_aMutex);
     495           0 :     ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
     496             : 
     497             :     // first check the meta data
     498           0 :     Reference<XDatabaseMetaData> xMeta = Reference< XConnection > (m_xParent, UNO_QUERY)->getMetaData();
     499           0 :     if (!xMeta.is() && !xMeta->supportsBatchUpdates())
     500           0 :         throwFunctionSequenceException(*this);
     501             : 
     502           0 :     OUString sSQL( impl_doEscapeProcessing_nothrow( _rSQL ) );
     503           0 :     Reference< XBatchExecution >(m_xAggregateAsSet, UNO_QUERY)->addBatch( sSQL );
     504           0 : }
     505             : 
     506           0 : void OStatement::clearBatch( ) throw( SQLException, RuntimeException, std::exception )
     507             : {
     508           0 :     MutexGuard aGuard(m_aMutex);
     509           0 :     ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
     510             :     // first check the meta data
     511           0 :     Reference<XDatabaseMetaData> xMeta = Reference< XConnection > (m_xParent, UNO_QUERY)->getMetaData();
     512           0 :     if (!xMeta.is() && !xMeta->supportsBatchUpdates())
     513           0 :         throwFunctionSequenceException(*this);
     514             : 
     515           0 :     Reference< XBatchExecution >(m_xAggregateAsSet, UNO_QUERY)->clearBatch();
     516           0 : }
     517             : 
     518           0 : Sequence< sal_Int32 > OStatement::executeBatch( ) throw( SQLException, RuntimeException, std::exception )
     519             : {
     520           0 :     MutexGuard aGuard(m_aMutex);
     521           0 :     ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
     522             :     // first check the meta data
     523           0 :     Reference<XDatabaseMetaData> xMeta = Reference< XConnection > (m_xParent, UNO_QUERY)->getMetaData();
     524           0 :     if (!xMeta.is() && !xMeta->supportsBatchUpdates())
     525           0 :         throwFunctionSequenceException(*this);
     526           0 :     return Reference< XBatchExecution >(m_xAggregateAsSet, UNO_QUERY)->executeBatch( );
     527             : }
     528             : 
     529             : 
     530           0 : Reference< XConnection > OStatement::getConnection(void) throw( SQLException, RuntimeException, std::exception )
     531             : {
     532           0 :     return Reference< XConnection >( m_xParent, UNO_QUERY );
     533             : }
     534             : 
     535          26 : void SAL_CALL OStatement::disposing()
     536             : {
     537          26 :     OStatementBase::disposing();
     538          26 :     m_xComposer.clear();
     539          26 :     m_xAggregateStatement.clear();
     540          26 : }
     541             : 
     542          30 : OUString OStatement::impl_doEscapeProcessing_nothrow( const OUString& _rSQL ) const
     543             : {
     544          30 :     if ( !m_bEscapeProcessing )
     545          22 :         return _rSQL;
     546             :     try
     547             :     {
     548           8 :         if ( !impl_ensureComposer_nothrow() )
     549           0 :             return _rSQL;
     550             : 
     551           8 :         bool bParseable = false;
     552           8 :         try { m_xComposer->setQuery( _rSQL ); bParseable = true; }
     553           0 :         catch( const SQLException& ) { }
     554             : 
     555           8 :         if ( !bParseable )
     556             :             // if we cannot parse it, silently accept this. The driver is probably able to cope with it then
     557           0 :             return _rSQL;
     558             : 
     559           8 :         OUString sLowLevelSQL = m_xComposer->getQueryWithSubstitution();
     560           8 :         return sLowLevelSQL;
     561             :     }
     562           0 :     catch( const Exception& )
     563             :     {
     564             :         DBG_UNHANDLED_EXCEPTION();
     565             :     }
     566             : 
     567           0 :     return _rSQL;
     568             : }
     569             : 
     570           8 : bool OStatement::impl_ensureComposer_nothrow() const
     571             : {
     572           8 :     if ( m_bAttemptedComposerCreation )
     573           4 :         return m_xComposer.is();
     574             : 
     575           4 :     const_cast< OStatement* >( this )->m_bAttemptedComposerCreation = true;
     576             :     try
     577             :     {
     578           4 :         Reference< XMultiServiceFactory > xFactory( m_xParent, UNO_QUERY_THROW );
     579           4 :         const_cast< OStatement* >( this )->m_xComposer.set( xFactory->createInstance( SERVICE_NAME_SINGLESELECTQUERYCOMPOSER ), UNO_QUERY_THROW );
     580             :     }
     581           0 :     catch( const Exception& )
     582             :     {
     583             :         DBG_UNHANDLED_EXCEPTION();
     584             :     }
     585             : 
     586           4 :     return m_xComposer.is();
     587             : }
     588             : 
     589             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10