LCOV - code coverage report
Current view: top level - dbaccess/source/core/api - statement.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 287 0.0 %
Date: 2014-04-14 Functions: 0 45 0.0 %
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           0 : OStatementBase::OStatementBase(const Reference< XConnection > & _xConn,
      46             :                                const Reference< XInterface > & _xStatement)
      47             :     :OSubComponent(m_aMutex, _xConn)
      48             :     ,OPropertySetHelper(OComponentHelper::rBHelper)
      49             :     ,m_bUseBookmarks( sal_False )
      50           0 :     ,m_bEscapeProcessing( sal_True )
      51             : 
      52             : {
      53             :     SAL_INFO("dbaccess", "OStatementBase::OStatementBase" );
      54             :     OSL_ENSURE(_xStatement.is() ,"Statement is NULL!");
      55           0 :     m_xAggregateAsSet.set(_xStatement,UNO_QUERY);
      56           0 :     m_xAggregateAsCancellable = Reference< ::com::sun::star::util::XCancellable > (m_xAggregateAsSet, UNO_QUERY);
      57           0 : }
      58             : 
      59           0 : OStatementBase::~OStatementBase()
      60             : {
      61           0 : }
      62             : 
      63             : // com::sun::star::lang::XTypeProvider
      64           0 : Sequence< Type > OStatementBase::getTypes() throw (RuntimeException, std::exception)
      65             : {
      66             :     SAL_INFO("dbaccess", "OStatementBase::getTypes" );
      67           0 :     OTypeCollection aTypes(::getCppuType( (const Reference< XPropertySet > *)0 ),
      68           0 :                            ::getCppuType( (const Reference< XWarningsSupplier > *)0 ),
      69           0 :                            ::getCppuType( (const Reference< XCloseable > *)0 ),
      70           0 :                            ::getCppuType( (const Reference< XMultipleResults > *)0 ),
      71           0 :                            ::getCppuType( (const Reference< ::com::sun::star::util::XCancellable > *)0 ),
      72           0 :                             OSubComponent::getTypes() );
      73           0 :     Reference< XGeneratedResultSet > xGRes(m_xAggregateAsSet, UNO_QUERY);
      74           0 :     if ( xGRes.is() )
      75           0 :         aTypes = OTypeCollection(::getCppuType( (const Reference< XGeneratedResultSet > *)0 ),aTypes.getTypes());
      76           0 :     Reference< XPreparedBatchExecution > xPreparedBatchExecution(m_xAggregateAsSet, UNO_QUERY);
      77           0 :     if ( xPreparedBatchExecution.is() )
      78           0 :         aTypes = OTypeCollection(::getCppuType( (const Reference< XPreparedBatchExecution > *)0 ),aTypes.getTypes());
      79             : 
      80           0 :     return aTypes.getTypes();
      81             : }
      82             : 
      83             : // com::sun::star::uno::XInterface
      84           0 : Any OStatementBase::queryInterface( const Type & rType ) throw (RuntimeException, std::exception)
      85             : {
      86           0 :     Any aIface = OSubComponent::queryInterface( rType );
      87           0 :     if (!aIface.hasValue())
      88             :     {
      89           0 :         aIface = ::cppu::queryInterface(
      90             :                     rType,
      91             :                     static_cast< XPropertySet * >( this ),
      92             :                     static_cast< XWarningsSupplier * >( this ),
      93             :                     static_cast< XCloseable * >( this ),
      94             :                     static_cast< XMultipleResults * >( this ),
      95           0 :                     static_cast< ::com::sun::star::util::XCancellable * >( this ));
      96           0 :         if ( !aIface.hasValue() )
      97             :         {
      98           0 :             Reference< XGeneratedResultSet > xGRes(m_xAggregateAsSet, UNO_QUERY);
      99           0 :             if ( ::getCppuType( (const Reference< XGeneratedResultSet > *)0 ) == rType && xGRes.is() )
     100           0 :                 aIface = ::cppu::queryInterface(rType,static_cast< XGeneratedResultSet * >( this ));
     101             :         }
     102           0 :         if ( !aIface.hasValue() )
     103             :         {
     104           0 :             Reference< XPreparedBatchExecution > xGRes(m_xAggregateAsSet, UNO_QUERY);
     105           0 :             if ( ::getCppuType( (const Reference< XPreparedBatchExecution > *)0 ) == rType && xGRes.is() )
     106           0 :                 aIface = ::cppu::queryInterface(rType,static_cast< XPreparedBatchExecution * >( this ));
     107             :         }
     108             :     }
     109           0 :     return aIface;
     110             : }
     111             : 
     112           0 : void OStatementBase::acquire() throw ()
     113             : {
     114           0 :     OSubComponent::acquire();
     115           0 : }
     116             : 
     117           0 : void OStatementBase::release() throw ()
     118             : {
     119           0 :     OSubComponent::release();
     120           0 : }
     121             : 
     122           0 : void OStatementBase::disposeResultSet()
     123             : {
     124             :     SAL_INFO("dbaccess", "OStatementBase::disposeResultSet" );
     125             :     // free the cursor if alive
     126           0 :     Reference< XComponent > xComp(m_aResultSet.get(), UNO_QUERY);
     127           0 :     if (xComp.is())
     128           0 :         xComp->dispose();
     129           0 :     m_aResultSet = NULL;
     130           0 : }
     131             : 
     132             : // OComponentHelper
     133           0 : void OStatementBase::disposing()
     134             : {
     135             :     SAL_INFO("dbaccess", "OStatementBase::disposing" );
     136           0 :     OPropertySetHelper::disposing();
     137             : 
     138           0 :     MutexGuard aGuard(m_aMutex);
     139             : 
     140             :     // free pending results
     141           0 :     disposeResultSet();
     142             : 
     143             :     // free the original statement
     144             :     {
     145           0 :         MutexGuard aCancelGuard(m_aCancelMutex);
     146           0 :         m_xAggregateAsCancellable = NULL;
     147             :     }
     148             : 
     149           0 :     if ( m_xAggregateAsSet.is() )
     150             :     {
     151             :         try
     152             :         {
     153           0 :             Reference< XCloseable > (m_xAggregateAsSet, UNO_QUERY)->close();
     154             :         }
     155           0 :         catch(RuntimeException& )
     156             :         {// don't care for anymore
     157             :         }
     158             :     }
     159           0 :     m_xAggregateAsSet = NULL;
     160             : 
     161             :     // free the parent at last
     162           0 :     OSubComponent::disposing();
     163           0 : }
     164             : 
     165             : // XCloseable
     166           0 : void OStatementBase::close(void) throw( SQLException, RuntimeException, std::exception )
     167             : {
     168             :     SAL_INFO("dbaccess", "OStatementBase::close" );
     169             :     {
     170           0 :         MutexGuard aGuard( m_aMutex );
     171           0 :         ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
     172             :     }
     173           0 :     dispose();
     174           0 : }
     175             : 
     176             : // OPropertySetHelper
     177           0 : Reference< XPropertySetInfo > OStatementBase::getPropertySetInfo() throw (RuntimeException, std::exception)
     178             : {
     179             :     SAL_INFO("dbaccess", "OStatementBase::getPropertySetInfo" );
     180           0 :     return createPropertySetInfo( getInfoHelper() ) ;
     181             : }
     182             : 
     183             : // comphelper::OPropertyArrayUsageHelper
     184           0 : ::cppu::IPropertyArrayHelper* OStatementBase::createArrayHelper( ) const
     185             : {
     186             :     //SAL_INFO("dbaccess", "OStatementBase::createArrayHelper" );
     187           0 :     BEGIN_PROPERTY_HELPER(10)
     188           0 :         DECL_PROP0(CURSORNAME,              OUString);
     189           0 :         DECL_PROP0_BOOL(ESCAPE_PROCESSING);
     190           0 :         DECL_PROP0(FETCHDIRECTION,          sal_Int32);
     191           0 :         DECL_PROP0(FETCHSIZE,               sal_Int32);
     192           0 :         DECL_PROP0(MAXFIELDSIZE,            sal_Int32);
     193           0 :         DECL_PROP0(MAXROWS,                 sal_Int32);
     194           0 :         DECL_PROP0(QUERYTIMEOUT,            sal_Int32);
     195           0 :         DECL_PROP0(RESULTSETCONCURRENCY,    sal_Int32);
     196           0 :         DECL_PROP0(RESULTSETTYPE,           sal_Int32);
     197           0 :         DECL_PROP0_BOOL(USEBOOKMARKS);
     198           0 :     END_PROPERTY_HELPER();
     199             : }
     200             : 
     201             : // cppu::OPropertySetHelper
     202           0 : ::cppu::IPropertyArrayHelper& OStatementBase::getInfoHelper()
     203             : {
     204             :     //SAL_INFO("dbaccess", "OStatementBase::getInfoHelper" );
     205           0 :     return *getArrayHelper();
     206             : }
     207             : 
     208           0 : sal_Bool OStatementBase::convertFastPropertyValue( Any & rConvertedValue, Any & rOldValue, sal_Int32 nHandle, const Any& rValue ) throw( IllegalArgumentException  )
     209             : {
     210             :     //SAL_INFO("dbaccess", "OStatementBase::convertFastPropertyValue" );
     211           0 :     sal_Bool bModified(sal_False);
     212           0 :     switch (nHandle)
     213             :     {
     214             :         case PROPERTY_ID_USEBOOKMARKS:
     215           0 :             bModified = ::comphelper::tryPropertyValue( rConvertedValue, rOldValue, rValue, m_bUseBookmarks );
     216           0 :             break;
     217             : 
     218             :         case PROPERTY_ID_ESCAPE_PROCESSING:
     219           0 :             bModified = ::comphelper::tryPropertyValue( rConvertedValue, rOldValue, rValue, m_bEscapeProcessing );
     220           0 :             break;
     221             : 
     222             :         default:
     223           0 :             if ( m_xAggregateAsSet.is() )
     224             :             {
     225             :                 // get the property name
     226           0 :                 OUString sPropName;
     227           0 :                 getInfoHelper().fillPropertyMembersByHandle( &sPropName, NULL, nHandle );
     228             : 
     229             :                 // now set the value
     230           0 :                 Any aCurrentValue = m_xAggregateAsSet->getPropertyValue( sPropName );
     231           0 :                 if ( aCurrentValue != rValue )
     232             :                 {
     233           0 :                     rOldValue = aCurrentValue;
     234           0 :                     rConvertedValue = rValue;
     235           0 :                     bModified = sal_True;
     236           0 :                 }
     237             :             }
     238           0 :             break;
     239             :     }
     240           0 :     return bModified;
     241             : }
     242             : 
     243           0 : void OStatementBase::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const Any& rValue ) throw (Exception, std::exception)
     244             : {
     245             :     //SAL_INFO("dbaccess", "OStatementBase::setFastPropertyValue_NoBroadcast" );
     246           0 :     switch ( nHandle )
     247             :     {
     248             :         case PROPERTY_ID_USEBOOKMARKS:
     249             :         {
     250           0 :             m_bUseBookmarks = ::comphelper::getBOOL( rValue );
     251           0 :             if ( m_xAggregateAsSet.is() && m_xAggregateAsSet->getPropertySetInfo()->hasPropertyByName( PROPERTY_USEBOOKMARKS ) )
     252           0 :                 m_xAggregateAsSet->setPropertyValue( PROPERTY_USEBOOKMARKS, rValue );
     253             :         }
     254           0 :         break;
     255             : 
     256             :         case PROPERTY_ID_ESCAPE_PROCESSING:
     257           0 :             m_bEscapeProcessing = ::comphelper::getBOOL( rValue );
     258           0 :             if ( m_xAggregateAsSet.is() )
     259           0 :                 m_xAggregateAsSet->setPropertyValue( PROPERTY_ESCAPE_PROCESSING, rValue );
     260           0 :             break;
     261             : 
     262             :         default:
     263           0 :             if ( m_xAggregateAsSet.is() )
     264             :             {
     265           0 :                 OUString sPropName;
     266           0 :                 getInfoHelper().fillPropertyMembersByHandle( &sPropName, NULL, nHandle );
     267           0 :                 m_xAggregateAsSet->setPropertyValue( sPropName, rValue );
     268             :             }
     269           0 :             break;
     270             :     }
     271           0 : }
     272             : 
     273           0 : void OStatementBase::getFastPropertyValue( Any& rValue, sal_Int32 nHandle ) const
     274             : {
     275             :     //SAL_INFO("dbaccess", "OStatementBase::getFastPropertyValue" );
     276           0 :     switch (nHandle)
     277             :     {
     278             :         case PROPERTY_ID_USEBOOKMARKS:
     279           0 :             rValue <<= m_bUseBookmarks;
     280           0 :             break;
     281             : 
     282             :         case PROPERTY_ID_ESCAPE_PROCESSING:
     283             :             // don't rely on our aggregate - if it implements this wrong, and always returns
     284             :             // TRUE here, then we would loop in impl_doEscapeProcessing_nothrow
     285           0 :             rValue <<= m_bEscapeProcessing;
     286           0 :             break;
     287             : 
     288             :         default:
     289           0 :             if ( m_xAggregateAsSet.is() )
     290             :             {
     291           0 :                 OUString sPropName;
     292           0 :                 const_cast< OStatementBase* >( this )->getInfoHelper().fillPropertyMembersByHandle( &sPropName, NULL, nHandle );
     293           0 :                 rValue = m_xAggregateAsSet->getPropertyValue( sPropName );
     294             :             }
     295           0 :             break;
     296             :     }
     297           0 : }
     298             : 
     299             : // XWarningsSupplier
     300           0 : Any OStatementBase::getWarnings(void) throw( SQLException, RuntimeException, std::exception )
     301             : {
     302             :     SAL_INFO("dbaccess", "OStatementBase::getWarnings" );
     303           0 :     MutexGuard aGuard(m_aMutex);
     304           0 :     ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
     305             : 
     306           0 :     return Reference< XWarningsSupplier >(m_xAggregateAsSet, UNO_QUERY)->getWarnings();
     307             : }
     308             : 
     309           0 : void OStatementBase::clearWarnings(void) throw( SQLException, RuntimeException, std::exception )
     310             : {
     311             :     SAL_INFO("dbaccess", "OStatementBase::clearWarnings" );
     312           0 :     MutexGuard aGuard(m_aMutex);
     313           0 :     ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
     314             : 
     315           0 :     Reference< XWarningsSupplier >(m_xAggregateAsSet, UNO_QUERY)->clearWarnings();
     316           0 : }
     317             : 
     318             : // ::com::sun::star::util::XCancellable
     319           0 : void OStatementBase::cancel(void) throw( RuntimeException, std::exception )
     320             : {
     321             :     SAL_INFO("dbaccess", "OStatementBase::cancel" );
     322             :     // no blocking as cancel is typically called from a different thread
     323           0 :     ClearableMutexGuard aCancelGuard(m_aCancelMutex);
     324           0 :     if (m_xAggregateAsCancellable.is())
     325           0 :         m_xAggregateAsCancellable->cancel();
     326             :     // else do nothing
     327           0 : }
     328             : 
     329             : // XMultipleResults
     330           0 : Reference< XResultSet > SAL_CALL OStatementBase::getResultSet(  ) throw(SQLException, RuntimeException, std::exception)
     331             : {
     332             :     SAL_INFO("dbaccess", "OStatementBase::getResultSet" );
     333           0 :     MutexGuard aGuard(m_aMutex);
     334           0 :     ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
     335             : 
     336             :     // first check the meta data
     337           0 :     Reference<XDatabaseMetaData> xMeta = Reference< XConnection > (m_xParent, UNO_QUERY)->getMetaData();
     338           0 :     if (!xMeta.is() && !xMeta->supportsMultipleResultSets())
     339           0 :         throwFunctionSequenceException(*this);
     340             : 
     341           0 :     return Reference< XMultipleResults >(m_xAggregateAsSet, UNO_QUERY)->getResultSet();
     342             : }
     343             : 
     344           0 : sal_Int32 SAL_CALL OStatementBase::getUpdateCount(  ) throw(SQLException, RuntimeException, std::exception)
     345             : {
     346             :     SAL_INFO("dbaccess", "OStatementBase::getUpdateCount" );
     347           0 :     MutexGuard aGuard(m_aMutex);
     348           0 :     ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
     349             : 
     350             :     // first check the meta data
     351           0 :     Reference<XDatabaseMetaData> xMeta = Reference< XConnection > (m_xParent, UNO_QUERY)->getMetaData();
     352           0 :     if (!xMeta.is() && !xMeta->supportsMultipleResultSets())
     353           0 :         throwFunctionSequenceException(*this);
     354             : 
     355           0 :     return Reference< XMultipleResults >(m_xAggregateAsSet, UNO_QUERY)->getUpdateCount();
     356             : }
     357             : 
     358           0 : sal_Bool SAL_CALL OStatementBase::getMoreResults(  ) throw(SQLException, RuntimeException, std::exception)
     359             : {
     360             :     SAL_INFO("dbaccess", "OStatementBase::getMoreResults" );
     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->supportsMultipleResultSets())
     367           0 :         throwFunctionSequenceException(*this);
     368             : 
     369             :     // free the previous results
     370           0 :     disposeResultSet();
     371             : 
     372           0 :     return Reference< XMultipleResults >(m_xAggregateAsSet, UNO_QUERY)->getMoreResults();
     373             : }
     374             : 
     375             : // XPreparedBatchExecution
     376           0 : void SAL_CALL OStatementBase::addBatch(  ) throw(SQLException, RuntimeException, std::exception)
     377             : {
     378             :     SAL_INFO("dbaccess", "OStatementBase::addBatch" );
     379           0 :     MutexGuard aGuard(m_aMutex);
     380           0 :     ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
     381             : 
     382             :     // first check the meta data
     383           0 :     Reference<XDatabaseMetaData> xMeta = Reference< XConnection > (m_xParent, UNO_QUERY)->getMetaData();
     384           0 :     if (!xMeta.is() && !xMeta->supportsBatchUpdates())
     385           0 :         throwFunctionSequenceException(*this);
     386             : 
     387           0 :     Reference< XPreparedBatchExecution >(m_xAggregateAsSet, UNO_QUERY)->addBatch();
     388           0 : }
     389             : 
     390           0 : void SAL_CALL OStatementBase::clearBatch(  ) throw(SQLException, RuntimeException, std::exception)
     391             : {
     392             :     SAL_INFO("dbaccess", "OStatementBase::clearBatch" );
     393           0 :     MutexGuard aGuard(m_aMutex);
     394           0 :     ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
     395             : 
     396             :     // first check the meta data
     397           0 :     Reference<XDatabaseMetaData> xMeta = Reference< XConnection > (m_xParent, UNO_QUERY)->getMetaData();
     398           0 :     if (!xMeta.is() && !xMeta->supportsBatchUpdates())
     399           0 :         throwFunctionSequenceException(*this);
     400             : 
     401           0 :     Reference< XPreparedBatchExecution >(m_xAggregateAsSet, UNO_QUERY)->clearBatch();
     402           0 : }
     403             : 
     404           0 : Sequence< sal_Int32 > SAL_CALL OStatementBase::executeBatch(  ) throw(SQLException, RuntimeException, std::exception)
     405             : {
     406             :     SAL_INFO("dbaccess", "OStatementBase::executeBatch" );
     407           0 :     MutexGuard aGuard(m_aMutex);
     408           0 :     ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
     409             : 
     410             :     // first check the meta data
     411           0 :     Reference<XDatabaseMetaData> xMeta = Reference< XConnection > (m_xParent, UNO_QUERY)->getMetaData();
     412           0 :     if (!xMeta.is() && !xMeta->supportsBatchUpdates())
     413           0 :         throwFunctionSequenceException(*this);
     414             : 
     415             :     // free the previous results
     416           0 :     disposeResultSet();
     417             : 
     418           0 :     return Reference< XPreparedBatchExecution >(m_xAggregateAsSet, UNO_QUERY)->executeBatch();
     419             : }
     420             : 
     421           0 : Reference< XResultSet > SAL_CALL OStatementBase::getGeneratedValues(  ) throw (SQLException, RuntimeException, std::exception)
     422             : {
     423             :     SAL_INFO("dbaccess", "OStatementBase::getGeneratedValues" );
     424           0 :     MutexGuard aGuard(m_aMutex);
     425           0 :     ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
     426           0 :     Reference< XGeneratedResultSet > xGRes(m_xAggregateAsSet, UNO_QUERY);
     427             : 
     428           0 :     if ( xGRes.is() )
     429           0 :         return xGRes->getGeneratedValues(  );
     430           0 :     return Reference< XResultSet >();
     431             : }
     432             : 
     433             : 
     434             : //  OStatement
     435             : 
     436           0 : OStatement::OStatement( const Reference< XConnection >& _xConn, const Reference< XInterface > & _xStatement )
     437             :     :OStatementBase( _xConn, _xStatement )
     438           0 :     ,m_bAttemptedComposerCreation( false )
     439             : {
     440             :     SAL_INFO("dbaccess", "OStatement::OStatement" );
     441           0 :     m_xAggregateStatement.set( _xStatement, UNO_QUERY_THROW );
     442           0 : }
     443             : 
     444           0 : IMPLEMENT_FORWARD_XINTERFACE2( OStatement, OStatementBase, OStatement_IFACE );
     445           0 : IMPLEMENT_FORWARD_XTYPEPROVIDER2( OStatement, OStatementBase, OStatement_IFACE );
     446             : 
     447             : // XServiceInfo
     448           0 : OUString OStatement::getImplementationName(  ) throw(RuntimeException, std::exception)
     449             : {
     450             :     SAL_INFO("dbaccess", "OStatement::getImplementationName" );
     451           0 :     return OUString("com.sun.star.sdb.OStatement");
     452             : }
     453             : 
     454           0 : sal_Bool OStatement::supportsService( const OUString& _rServiceName ) throw (RuntimeException, std::exception)
     455             : {
     456           0 :     return cppu::supportsService(this, _rServiceName);
     457             : }
     458             : 
     459           0 : Sequence< OUString > OStatement::getSupportedServiceNames(  ) throw (RuntimeException, std::exception)
     460             : {
     461             :     SAL_INFO("dbaccess", "OStatement::getSupportedServiceNames" );
     462           0 :     Sequence< OUString > aSNS( 1 );
     463           0 :     aSNS.getArray()[0] = SERVICE_SDBC_STATEMENT;
     464           0 :     return aSNS;
     465             : }
     466             : 
     467             : // XStatement
     468           0 : Reference< XResultSet > OStatement::executeQuery( const OUString& _rSQL ) throw( SQLException, RuntimeException, std::exception )
     469             : {
     470             :     SAL_INFO("dbaccess", "OStatement::executeQuery" );
     471           0 :     MutexGuard aGuard(m_aMutex);
     472           0 :     ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
     473             : 
     474           0 :     disposeResultSet();
     475           0 :     Reference< XResultSet > xResultSet;
     476             : 
     477           0 :     OUString sSQL( impl_doEscapeProcessing_nothrow( _rSQL ) );
     478             : 
     479           0 :     Reference< XResultSet > xInnerResultSet = m_xAggregateStatement->executeQuery( sSQL );
     480           0 :     Reference< XConnection > xConnection( m_xParent, UNO_QUERY_THROW );
     481             : 
     482           0 :     if ( xInnerResultSet.is() )
     483             :     {
     484           0 :         Reference< XDatabaseMetaData > xMeta = xConnection->getMetaData();
     485           0 :         sal_Bool bCaseSensitive = xMeta.is() && xMeta->supportsMixedCaseQuotedIdentifiers();
     486           0 :         xResultSet = new OResultSet( xInnerResultSet, *this, bCaseSensitive );
     487             : 
     488             :         // keep the resultset weak
     489           0 :         m_aResultSet = xResultSet;
     490             :     }
     491             : 
     492           0 :     return xResultSet;
     493             : }
     494             : 
     495           0 : sal_Int32 OStatement::executeUpdate( const OUString& _rSQL ) throw( SQLException, RuntimeException, std::exception )
     496             : {
     497             :     SAL_INFO("dbaccess", "OStatement::executeUpdate" );
     498           0 :     MutexGuard aGuard(m_aMutex);
     499           0 :     ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
     500             : 
     501           0 :     disposeResultSet();
     502             : 
     503           0 :     OUString sSQL( impl_doEscapeProcessing_nothrow( _rSQL ) );
     504           0 :     return m_xAggregateStatement->executeUpdate( sSQL );
     505             : }
     506             : 
     507           0 : sal_Bool OStatement::execute( const OUString& _rSQL ) throw( SQLException, RuntimeException, std::exception )
     508             : {
     509             :     SAL_INFO("dbaccess", "OStatement::execute" );
     510           0 :     MutexGuard aGuard(m_aMutex);
     511           0 :     ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
     512             : 
     513           0 :     disposeResultSet();
     514             : 
     515           0 :     OUString sSQL( impl_doEscapeProcessing_nothrow( _rSQL ) );
     516           0 :     return m_xAggregateStatement->execute( sSQL );
     517             : }
     518             : 
     519           0 : void OStatement::addBatch( const OUString& _rSQL ) throw( SQLException, RuntimeException, std::exception )
     520             : {
     521             :     SAL_INFO("dbaccess", "OStatement::execute" );
     522           0 :     MutexGuard aGuard(m_aMutex);
     523           0 :     ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
     524             : 
     525             :     // first check the meta data
     526           0 :     Reference<XDatabaseMetaData> xMeta = Reference< XConnection > (m_xParent, UNO_QUERY)->getMetaData();
     527           0 :     if (!xMeta.is() && !xMeta->supportsBatchUpdates())
     528           0 :         throwFunctionSequenceException(*this);
     529             : 
     530           0 :     OUString sSQL( impl_doEscapeProcessing_nothrow( _rSQL ) );
     531           0 :     Reference< XBatchExecution >(m_xAggregateAsSet, UNO_QUERY)->addBatch( sSQL );
     532           0 : }
     533             : 
     534           0 : void OStatement::clearBatch( ) throw( SQLException, RuntimeException, std::exception )
     535             : {
     536             :     SAL_INFO("dbaccess", "OStatement::execute" );
     537           0 :     MutexGuard aGuard(m_aMutex);
     538           0 :     ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
     539             :     // first check the meta data
     540           0 :     Reference<XDatabaseMetaData> xMeta = Reference< XConnection > (m_xParent, UNO_QUERY)->getMetaData();
     541           0 :     if (!xMeta.is() && !xMeta->supportsBatchUpdates())
     542           0 :         throwFunctionSequenceException(*this);
     543             : 
     544           0 :     Reference< XBatchExecution >(m_xAggregateAsSet, UNO_QUERY)->clearBatch();
     545           0 : }
     546             : 
     547           0 : Sequence< sal_Int32 > OStatement::executeBatch( ) throw( SQLException, RuntimeException, std::exception )
     548             : {
     549             :     SAL_INFO("dbaccess", "OStatement::execute" );
     550           0 :     MutexGuard aGuard(m_aMutex);
     551           0 :     ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
     552             :     // first check the meta data
     553           0 :     Reference<XDatabaseMetaData> xMeta = Reference< XConnection > (m_xParent, UNO_QUERY)->getMetaData();
     554           0 :     if (!xMeta.is() && !xMeta->supportsBatchUpdates())
     555           0 :         throwFunctionSequenceException(*this);
     556           0 :     return Reference< XBatchExecution >(m_xAggregateAsSet, UNO_QUERY)->executeBatch( );
     557             : }
     558             : 
     559             : 
     560           0 : Reference< XConnection > OStatement::getConnection(void) throw( SQLException, RuntimeException, std::exception )
     561             : {
     562             :     SAL_INFO("dbaccess", "OStatement::getConnection" );
     563           0 :     return Reference< XConnection >( m_xParent, UNO_QUERY );
     564             : }
     565             : 
     566           0 : void SAL_CALL OStatement::disposing()
     567             : {
     568             :     SAL_INFO("dbaccess", "OStatement::disposing" );
     569           0 :     OStatementBase::disposing();
     570           0 :     m_xComposer.clear();
     571           0 :     m_xAggregateStatement.clear();
     572           0 : }
     573             : 
     574           0 : OUString OStatement::impl_doEscapeProcessing_nothrow( const OUString& _rSQL ) const
     575             : {
     576             :     SAL_INFO("dbaccess", "OStatement::impl_doEscapeProcessing_nothrow" );
     577           0 :     if ( !m_bEscapeProcessing )
     578           0 :         return _rSQL;
     579             :     try
     580             :     {
     581           0 :         if ( !impl_ensureComposer_nothrow() )
     582           0 :             return _rSQL;
     583             : 
     584           0 :         bool bParseable = false;
     585           0 :         try { m_xComposer->setQuery( _rSQL ); bParseable = true; }
     586           0 :         catch( const SQLException& ) { }
     587             : 
     588           0 :         if ( !bParseable )
     589             :             // if we cannot parse it, silently accept this. The driver is probably able to cope with it then
     590           0 :             return _rSQL;
     591             : 
     592           0 :         OUString sLowLevelSQL = m_xComposer->getQueryWithSubstitution();
     593           0 :         return sLowLevelSQL;
     594             :     }
     595           0 :     catch( const Exception& )
     596             :     {
     597             :         DBG_UNHANDLED_EXCEPTION();
     598             :     }
     599             : 
     600           0 :     return _rSQL;
     601             : }
     602             : 
     603           0 : bool OStatement::impl_ensureComposer_nothrow() const
     604             : {
     605             :     SAL_INFO("dbaccess", "OStatement::impl_ensureComposer_nothrow" );
     606           0 :     if ( m_bAttemptedComposerCreation )
     607           0 :         return m_xComposer.is();
     608             : 
     609           0 :     const_cast< OStatement* >( this )->m_bAttemptedComposerCreation = true;
     610             :     try
     611             :     {
     612           0 :         Reference< XMultiServiceFactory > xFactory( m_xParent, UNO_QUERY_THROW );
     613           0 :         const_cast< OStatement* >( this )->m_xComposer.set( xFactory->createInstance( SERVICE_NAME_SINGLESELECTQUERYCOMPOSER ), UNO_QUERY_THROW );
     614             :     }
     615           0 :     catch( const Exception& )
     616             :     {
     617             :         DBG_UNHANDLED_EXCEPTION();
     618             :     }
     619             : 
     620           0 :     return m_xComposer.is();
     621             : }
     622             : 
     623             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10