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

Generated by: LCOV version 1.10