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

Generated by: LCOV version 1.10