LCOV - code coverage report
Current view: top level - dbaccess/source/core/api - preparedstatement.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 50 205 24.4 %
Date: 2014-11-03 Functions: 11 41 26.8 %
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             : 
      21             : #include "dbastrings.hrc"
      22             : 
      23             : #include <com/sun/star/lang/DisposedException.hpp>
      24             : #include <com/sun/star/sdbc/XConnection.hpp>
      25             : #include <com/sun/star/sdbc/XDatabaseMetaData.hpp>
      26             : 
      27             : #include <comphelper/property.hxx>
      28             : #include <comphelper/sequence.hxx>
      29             : #include <cppuhelper/supportsservice.hxx>
      30             : #include <cppuhelper/typeprovider.hxx>
      31             : #include <preparedstatement.hxx>
      32             : #include <resultcolumn.hxx>
      33             : #include <resultset.hxx>
      34             : #include <tools/debug.hxx>
      35             : #include <tools/diagnose_ex.h>
      36             : 
      37             : using namespace ::com::sun::star::sdbc;
      38             : using namespace ::com::sun::star::sdbcx;
      39             : using namespace ::com::sun::star::beans;
      40             : using namespace ::com::sun::star::uno;
      41             : using namespace ::com::sun::star::lang;
      42             : using namespace ::cppu;
      43             : using namespace ::osl;
      44             : using namespace dbaccess;
      45             : 
      46             : 
      47          88 : OPreparedStatement::OPreparedStatement(const Reference< XConnection > & _xConn,
      48             :                                       const Reference< XInterface > & _xStatement)
      49          88 :                    :OStatementBase(_xConn, _xStatement)
      50             : {
      51          88 :     m_xAggregateAsParameters = Reference< XParameters >( m_xAggregateAsSet, UNO_QUERY_THROW );
      52             : 
      53          88 :     Reference<XDatabaseMetaData> xMeta = _xConn->getMetaData();
      54          88 :     m_pColumns = new OColumns(*this, m_aMutex, xMeta.is() && xMeta->supportsMixedCaseQuotedIdentifiers(),::std::vector< OUString>(), NULL,NULL);
      55          88 : }
      56             : 
      57         264 : OPreparedStatement::~OPreparedStatement()
      58             : {
      59          88 :     m_pColumns->acquire();
      60          88 :     m_pColumns->disposing();
      61          88 :     delete m_pColumns;
      62             : 
      63         176 : }
      64             : 
      65             : // com::sun::star::lang::XTypeProvider
      66           0 : Sequence< Type > OPreparedStatement::getTypes() throw (RuntimeException, std::exception)
      67             : {
      68           0 :     OTypeCollection aTypes(cppu::UnoType<XServiceInfo>::get(),
      69           0 :                            cppu::UnoType<XPreparedStatement>::get(),
      70           0 :                            cppu::UnoType<XParameters>::get(),
      71           0 :                            cppu::UnoType<XResultSetMetaDataSupplier>::get(),
      72           0 :                            cppu::UnoType<XColumnsSupplier>::get(),
      73           0 :                             OStatementBase::getTypes() );
      74             : 
      75           0 :     return aTypes.getTypes();
      76             : }
      77             : 
      78           0 : Sequence< sal_Int8 > OPreparedStatement::getImplementationId() throw (RuntimeException, std::exception)
      79             : {
      80           0 :     return css::uno::Sequence<sal_Int8>();
      81             : }
      82             : 
      83             : // com::sun::star::uno::XInterface
      84         802 : Any OPreparedStatement::queryInterface( const Type & rType ) throw (RuntimeException, std::exception)
      85             : {
      86         802 :     Any aIface = OStatementBase::queryInterface( rType );
      87         802 :     if (!aIface.hasValue())
      88         480 :         aIface = ::cppu::queryInterface(
      89             :                     rType,
      90             :                     static_cast< XServiceInfo * >( this ),
      91             :                     static_cast< XParameters * >( this ),
      92             :                     static_cast< XColumnsSupplier * >( this ),
      93             :                     static_cast< XResultSetMetaDataSupplier * >( this ),
      94             :                     static_cast< XPreparedBatchExecution * >( this ),
      95             :                     static_cast< XMultipleResults * >( this ),
      96         240 :                     static_cast< XPreparedStatement * >( this ));
      97         802 :     return aIface;
      98             : }
      99             : 
     100        3268 : void OPreparedStatement::acquire() throw ()
     101             : {
     102        3268 :     OStatementBase::acquire();
     103        3268 : }
     104             : 
     105        3180 : void OPreparedStatement::release() throw ()
     106             : {
     107        3180 :     OStatementBase::release();
     108        3180 : }
     109             : 
     110             : // XServiceInfo
     111           0 : OUString OPreparedStatement::getImplementationName(  ) throw(RuntimeException, std::exception)
     112             : {
     113           0 :     return OUString("com.sun.star.sdb.OPreparedStatement");
     114             : }
     115             : 
     116           0 : sal_Bool OPreparedStatement::supportsService( const OUString& _rServiceName ) throw (RuntimeException, std::exception)
     117             : {
     118           0 :     return cppu::supportsService(this, _rServiceName);
     119             : }
     120             : 
     121           0 : Sequence< OUString > OPreparedStatement::getSupportedServiceNames(  ) throw (RuntimeException, std::exception)
     122             : {
     123           0 :     Sequence< OUString > aSNS( 2 );
     124           0 :     aSNS.getArray()[0] = SERVICE_SDBC_PREPAREDSTATEMENT;
     125           0 :     aSNS.getArray()[1] = SERVICE_SDB_PREPAREDSTATMENT;
     126           0 :     return aSNS;
     127             : }
     128             : 
     129             : // OComponentHelper
     130          88 : void OPreparedStatement::disposing()
     131             : {
     132             :     {
     133          88 :         MutexGuard aGuard(m_aMutex);
     134          88 :         m_pColumns->disposing();
     135          88 :         m_xAggregateAsParameters = NULL;
     136             :     }
     137          88 :     OStatementBase::disposing();
     138          88 : }
     139             : 
     140             : // ::com::sun::star::sdbcx::XColumnsSupplier
     141           0 : Reference< ::com::sun::star::container::XNameAccess > OPreparedStatement::getColumns(void) throw( RuntimeException, std::exception )
     142             : {
     143           0 :     MutexGuard aGuard(m_aMutex);
     144           0 :     ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
     145             : 
     146             :     // do we have to populate the columns
     147           0 :     if (!m_pColumns->isInitialized())
     148             :     {
     149             :         try
     150             :         {
     151           0 :             Reference< XResultSetMetaDataSupplier > xSuppMeta( m_xAggregateAsSet, UNO_QUERY_THROW );
     152           0 :             Reference< XResultSetMetaData > xMetaData( xSuppMeta->getMetaData(), UNO_SET_THROW );
     153             : 
     154           0 :             Reference< XConnection > xConn( getConnection(), UNO_SET_THROW );
     155           0 :             Reference< XDatabaseMetaData > xDBMeta( xConn->getMetaData(), UNO_SET_THROW );
     156             : 
     157           0 :             for (sal_Int32 i = 0, nCount = xMetaData->getColumnCount(); i < nCount; ++i)
     158             :             {
     159             :                 // retrieve the name of the column
     160           0 :                 OUString aName = xMetaData->getColumnName(i + 1);
     161           0 :                 OResultColumn* pColumn = new OResultColumn(xMetaData, i + 1, xDBMeta);
     162           0 :                 m_pColumns->append(aName, pColumn);
     163           0 :             }
     164             :         }
     165           0 :         catch (const SQLException& )
     166             :         {
     167             :             DBG_UNHANDLED_EXCEPTION();
     168             :         }
     169           0 :         m_pColumns->setInitialized();
     170             :     }
     171           0 :     return m_pColumns;
     172             : }
     173             : 
     174             : // XResultSetMetaDataSupplier
     175          48 : Reference< XResultSetMetaData > OPreparedStatement::getMetaData(void) throw( SQLException, RuntimeException, std::exception )
     176             : {
     177          48 :     MutexGuard aGuard(m_aMutex);
     178          48 :     ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
     179          48 :     return Reference< XResultSetMetaDataSupplier >( m_xAggregateAsSet, UNO_QUERY_THROW )->getMetaData();
     180             : }
     181             : 
     182             : // XPreparedStatement
     183          46 : Reference< XResultSet >  OPreparedStatement::executeQuery() throw( SQLException, RuntimeException, std::exception )
     184             : {
     185          46 :     MutexGuard aGuard(m_aMutex);
     186          46 :     ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
     187             : 
     188          46 :     disposeResultSet();
     189             : 
     190          46 :     Reference< XResultSet > xResultSet;
     191          92 :     Reference< XResultSet > xDrvResultSet = Reference< XPreparedStatement >( m_xAggregateAsSet, UNO_QUERY_THROW )->executeQuery();
     192          46 :     if (xDrvResultSet.is())
     193             :     {
     194          46 :         xResultSet = new OResultSet(xDrvResultSet, *this, m_pColumns->isCaseSensitive());
     195             : 
     196             :         // keep the resultset weak
     197          46 :         m_aResultSet = xResultSet;
     198             :     }
     199          92 :     return xResultSet;
     200             : }
     201             : 
     202           0 : sal_Int32 OPreparedStatement::executeUpdate() throw( SQLException, RuntimeException, std::exception )
     203             : {
     204           0 :     MutexGuard aGuard(m_aMutex);
     205           0 :     ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
     206             : 
     207           0 :     disposeResultSet();
     208             : 
     209           0 :     return Reference< XPreparedStatement >( m_xAggregateAsSet, UNO_QUERY_THROW )->executeUpdate();
     210             : }
     211             : 
     212           0 : sal_Bool OPreparedStatement::execute() throw( SQLException, RuntimeException, std::exception )
     213             : {
     214           0 :     MutexGuard aGuard(m_aMutex);
     215           0 :     ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
     216             : 
     217           0 :     disposeResultSet();
     218             : 
     219           0 :     return Reference< XPreparedStatement >( m_xAggregateAsSet, UNO_QUERY_THROW )->execute();
     220             : }
     221             : 
     222          50 : Reference< XConnection > OPreparedStatement::getConnection(void) throw( SQLException, RuntimeException, std::exception )
     223             : {
     224          50 :     return Reference< XConnection > (m_xParent, UNO_QUERY);
     225             : }
     226             : 
     227             : // XParameters
     228           0 : void SAL_CALL OPreparedStatement::setNull( sal_Int32 parameterIndex, sal_Int32 sqlType ) throw(SQLException, RuntimeException, std::exception)
     229             : {
     230           0 :     MutexGuard aGuard(m_aMutex);
     231           0 :     ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
     232             : 
     233           0 :     m_xAggregateAsParameters->setNull(parameterIndex, sqlType);
     234           0 : }
     235             : 
     236           0 : void SAL_CALL OPreparedStatement::setObjectNull( sal_Int32 parameterIndex, sal_Int32 sqlType, const OUString& typeName ) throw(SQLException, RuntimeException, std::exception)
     237             : {
     238           0 :     MutexGuard aGuard(m_aMutex);
     239           0 :     ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
     240             : 
     241           0 :     m_xAggregateAsParameters->setObjectNull(parameterIndex, sqlType, typeName);
     242           0 : }
     243             : 
     244           0 : void SAL_CALL OPreparedStatement::setBoolean( sal_Int32 parameterIndex, sal_Bool x ) throw(SQLException, RuntimeException, std::exception)
     245             : {
     246           0 :     MutexGuard aGuard(m_aMutex);
     247           0 :     ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
     248             : 
     249           0 :     m_xAggregateAsParameters->setBoolean(parameterIndex, x);
     250           0 : }
     251             : 
     252           0 : void SAL_CALL OPreparedStatement::setByte( sal_Int32 parameterIndex, sal_Int8 x ) throw(SQLException, RuntimeException, std::exception)
     253             : {
     254           0 :     MutexGuard aGuard(m_aMutex);
     255           0 :     ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
     256             : 
     257           0 :     m_xAggregateAsParameters->setByte(parameterIndex, x);
     258           0 : }
     259             : 
     260           0 : void SAL_CALL OPreparedStatement::setShort( sal_Int32 parameterIndex, sal_Int16 x ) throw(SQLException, RuntimeException, std::exception)
     261             : {
     262           0 :     MutexGuard aGuard(m_aMutex);
     263           0 :     ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
     264             : 
     265           0 :     m_xAggregateAsParameters->setShort(parameterIndex, x);
     266           0 : }
     267             : 
     268           0 : void SAL_CALL OPreparedStatement::setInt( sal_Int32 parameterIndex, sal_Int32 x ) throw(SQLException, RuntimeException, std::exception)
     269             : {
     270           0 :     MutexGuard aGuard(m_aMutex);
     271           0 :     ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
     272             : 
     273           0 :     m_xAggregateAsParameters->setInt(parameterIndex, x);
     274           0 : }
     275             : 
     276           0 : void SAL_CALL OPreparedStatement::setLong( sal_Int32 parameterIndex, sal_Int64 x ) throw(SQLException, RuntimeException, std::exception)
     277             : {
     278           0 :     MutexGuard aGuard(m_aMutex);
     279           0 :     ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
     280             : 
     281           0 :     m_xAggregateAsParameters->setLong(parameterIndex, x);
     282           0 : }
     283             : 
     284           0 : void SAL_CALL OPreparedStatement::setFloat( sal_Int32 parameterIndex, float x ) throw(SQLException, RuntimeException, std::exception)
     285             : {
     286           0 :     MutexGuard aGuard(m_aMutex);
     287           0 :     ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
     288             : 
     289           0 :     m_xAggregateAsParameters->setFloat(parameterIndex, x);
     290           0 : }
     291             : 
     292           0 : void SAL_CALL OPreparedStatement::setDouble( sal_Int32 parameterIndex, double x ) throw(SQLException, RuntimeException, std::exception)
     293             : {
     294           0 :     MutexGuard aGuard(m_aMutex);
     295           0 :     ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
     296             : 
     297           0 :     m_xAggregateAsParameters->setDouble(parameterIndex, x);
     298           0 : }
     299             : 
     300          10 : void SAL_CALL OPreparedStatement::setString( sal_Int32 parameterIndex, const OUString& x ) throw(SQLException, RuntimeException, std::exception)
     301             : {
     302          10 :     MutexGuard aGuard(m_aMutex);
     303          10 :     ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
     304             : 
     305          10 :     m_xAggregateAsParameters->setString(parameterIndex, x);
     306          10 : }
     307             : 
     308           0 : void SAL_CALL OPreparedStatement::setBytes( sal_Int32 parameterIndex, const Sequence< sal_Int8 >& x ) throw(SQLException, RuntimeException, std::exception)
     309             : {
     310           0 :     MutexGuard aGuard(m_aMutex);
     311           0 :     ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
     312             : 
     313           0 :     m_xAggregateAsParameters->setBytes(parameterIndex, x);
     314           0 : }
     315             : 
     316           0 : void SAL_CALL OPreparedStatement::setDate( sal_Int32 parameterIndex, const ::com::sun::star::util::Date& x ) throw(SQLException, RuntimeException, std::exception)
     317             : {
     318           0 :     MutexGuard aGuard(m_aMutex);
     319           0 :     ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
     320             : 
     321           0 :     m_xAggregateAsParameters->setDate(parameterIndex, x);
     322           0 : }
     323             : 
     324           0 : void SAL_CALL OPreparedStatement::setTime( sal_Int32 parameterIndex, const ::com::sun::star::util::Time& x ) throw(SQLException, RuntimeException, std::exception)
     325             : {
     326           0 :     MutexGuard aGuard(m_aMutex);
     327           0 :     ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
     328             : 
     329           0 :     m_xAggregateAsParameters->setTime(parameterIndex, x);
     330           0 : }
     331             : 
     332           0 : void SAL_CALL OPreparedStatement::setTimestamp( sal_Int32 parameterIndex, const ::com::sun::star::util::DateTime& x ) throw(SQLException, RuntimeException, std::exception)
     333             : {
     334           0 :     MutexGuard aGuard(m_aMutex);
     335           0 :     ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
     336             : 
     337           0 :     m_xAggregateAsParameters->setTimestamp(parameterIndex, x);
     338           0 : }
     339             : 
     340           0 : void SAL_CALL OPreparedStatement::setBinaryStream( sal_Int32 parameterIndex, const Reference< ::com::sun::star::io::XInputStream >& x, sal_Int32 length ) throw(SQLException, RuntimeException, std::exception)
     341             : {
     342           0 :     MutexGuard aGuard(m_aMutex);
     343           0 :     ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
     344             : 
     345           0 :     m_xAggregateAsParameters->setBinaryStream(parameterIndex, x, length);
     346           0 : }
     347             : 
     348           0 : void SAL_CALL OPreparedStatement::setCharacterStream( sal_Int32 parameterIndex, const Reference< ::com::sun::star::io::XInputStream >& x, sal_Int32 length ) throw(SQLException, RuntimeException, std::exception)
     349             : {
     350           0 :     MutexGuard aGuard(m_aMutex);
     351           0 :     ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
     352             : 
     353           0 :     m_xAggregateAsParameters->setCharacterStream(parameterIndex, x, length);
     354           0 : }
     355             : 
     356           0 : void SAL_CALL OPreparedStatement::setObject( sal_Int32 parameterIndex, const Any& x ) throw(SQLException, RuntimeException, std::exception)
     357             : {
     358           0 :     MutexGuard aGuard(m_aMutex);
     359           0 :     ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
     360             : 
     361           0 :     m_xAggregateAsParameters->setObject(parameterIndex, x);
     362           0 : }
     363             : 
     364           0 : void SAL_CALL OPreparedStatement::setObjectWithInfo( sal_Int32 parameterIndex, const Any& x, sal_Int32 targetSqlType, sal_Int32 scale ) throw(SQLException, RuntimeException, std::exception)
     365             : {
     366           0 :     MutexGuard aGuard(m_aMutex);
     367           0 :     ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
     368             : 
     369           0 :     m_xAggregateAsParameters->setObjectWithInfo(parameterIndex, x, targetSqlType, scale);
     370           0 : }
     371             : 
     372           0 : void SAL_CALL OPreparedStatement::setRef( sal_Int32 parameterIndex, const Reference< XRef >& x ) throw(SQLException, RuntimeException, std::exception)
     373             : {
     374           0 :     MutexGuard aGuard(m_aMutex);
     375           0 :     ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
     376             : 
     377           0 :     m_xAggregateAsParameters->setRef(parameterIndex, x);
     378           0 : }
     379             : 
     380           0 : void SAL_CALL OPreparedStatement::setBlob( sal_Int32 parameterIndex, const Reference< XBlob >& x ) throw(SQLException, RuntimeException, std::exception)
     381             : {
     382           0 :     MutexGuard aGuard(m_aMutex);
     383           0 :     ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
     384             : 
     385           0 :     m_xAggregateAsParameters->setBlob(parameterIndex, x);
     386           0 : }
     387             : 
     388           0 : void SAL_CALL OPreparedStatement::setClob( sal_Int32 parameterIndex, const Reference< XClob >& x ) throw(SQLException, RuntimeException, std::exception)
     389             : {
     390           0 :     MutexGuard aGuard(m_aMutex);
     391           0 :     ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
     392             : 
     393           0 :     m_xAggregateAsParameters->setClob(parameterIndex, x);
     394           0 : }
     395             : 
     396           0 : void SAL_CALL OPreparedStatement::setArray( sal_Int32 parameterIndex, const Reference< XArray >& x ) throw(SQLException, RuntimeException, std::exception)
     397             : {
     398           0 :     MutexGuard aGuard(m_aMutex);
     399           0 :     ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
     400             : 
     401           0 :     m_xAggregateAsParameters->setArray(parameterIndex, x);
     402           0 : }
     403             : 
     404           0 : void SAL_CALL OPreparedStatement::clearParameters(  ) throw(SQLException, RuntimeException, std::exception)
     405             : {
     406           0 :     MutexGuard aGuard(m_aMutex);
     407           0 :     ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
     408             : 
     409           0 :     m_xAggregateAsParameters->clearParameters();
     410           0 : }
     411             : 
     412             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10