LCOV - code coverage report
Current view: top level - connectivity/source/drivers/firebird - Statement.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 45 67 67.2 %
Date: 2014-11-03 Functions: 7 17 41.2 %
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 "Connection.hxx"
      21             : #include "Driver.hxx"
      22             : #include "ResultSet.hxx"
      23             : #include "Statement.hxx"
      24             : #include "Util.hxx"
      25             : 
      26             : #include <comphelper/sequence.hxx>
      27             : #include <osl/diagnose.h>
      28             : #include <osl/thread.h>
      29             : #include <rtl/ustrbuf.hxx>
      30             : 
      31             : #include <com/sun/star/lang/DisposedException.hpp>
      32             : #include <com/sun/star/sdbc/ResultSetConcurrency.hpp>
      33             : #include <com/sun/star/sdbc/ResultSetType.hpp>
      34             : #include <com/sun/star/sdbc/FetchDirection.hpp>
      35             : 
      36             : using namespace connectivity::firebird;
      37             : 
      38             : using namespace com::sun::star;
      39             : using namespace com::sun::star::uno;
      40             : using namespace com::sun::star::lang;
      41             : using namespace com::sun::star::beans;
      42             : using namespace com::sun::star::sdbc;
      43             : using namespace com::sun::star::sdbcx;
      44             : using namespace com::sun::star::container;
      45             : using namespace com::sun::star::io;
      46             : using namespace com::sun::star::util;
      47             : 
      48             : using namespace ::comphelper;
      49             : using namespace ::osl;
      50             : using namespace ::std;
      51             : 
      52             : // ---- XBatchExecution - UNSUPPORTED ----------------------------------------
      53           0 : void SAL_CALL OStatement::addBatch(const OUString& sql)
      54             :     throw(SQLException, RuntimeException, std::exception)
      55             : {
      56             :     (void) sql;
      57           0 : }
      58             : 
      59           0 : void SAL_CALL OStatement::clearBatch() throw(SQLException, RuntimeException, std::exception)
      60             : {
      61           0 : }
      62             : 
      63           0 : Sequence< sal_Int32 > SAL_CALL OStatement::executeBatch() throw(SQLException, RuntimeException, std::exception)
      64             : {
      65           0 :     return Sequence< sal_Int32 >();
      66             : }
      67             : 
      68           0 : IMPLEMENT_SERVICE_INFO(OStatement,"com.sun.star.sdbcx.OStatement","com.sun.star.sdbc.Statement");
      69             : 
      70         346 : void SAL_CALL OStatement::acquire() throw()
      71             : {
      72         346 :     OStatementCommonBase::acquire();
      73         346 : }
      74             : 
      75         346 : void SAL_CALL OStatement::release() throw()
      76             : {
      77         346 :     OStatementCommonBase::release();
      78         346 : }
      79             : 
      80          64 : void OStatement::disposeResultSet()
      81             : {
      82          64 :     MutexGuard aGuard(m_aMutex);
      83          64 :     checkDisposed(OStatementCommonBase_Base::rBHelper.bDisposed);
      84             : 
      85          64 :     OStatementCommonBase::disposeResultSet();
      86             : 
      87          64 :     if (m_pSqlda)
      88             :     {
      89          18 :         freeSQLVAR(m_pSqlda);
      90          18 :         free(m_pSqlda);
      91          18 :         m_pSqlda = 0;
      92          64 :     }
      93          64 : }
      94             : 
      95             : // ---- XStatement -----------------------------------------------------------
      96           0 : sal_Int32 SAL_CALL OStatement::executeUpdate(const OUString& sql)
      97             :     throw(SQLException, RuntimeException, std::exception)
      98             : {
      99           0 :     execute(sql);
     100           0 :     return getStatementChangeCount();
     101             : }
     102             : 
     103             : 
     104          18 : uno::Reference< XResultSet > SAL_CALL OStatement::executeQuery(const OUString& sql)
     105             :     throw(SQLException, RuntimeException, std::exception)
     106             : {
     107          18 :     MutexGuard aGuard(m_aMutex);
     108          18 :     checkDisposed(OStatementCommonBase_Base::rBHelper.bDisposed);
     109             : 
     110             :     SAL_INFO("connectivity.firebird", "executeQuery(" << sql << ")");
     111             : 
     112          18 :     ISC_STATUS aErr = 0;
     113             : 
     114          18 :     disposeResultSet();
     115             : 
     116             :     prepareAndDescribeStatement(sql,
     117          18 :                                 m_pSqlda);
     118             : 
     119             :     aErr = isc_dsql_execute(m_statusVector,
     120          18 :                             &m_pConnection->getTransaction(),
     121             :                             &m_aStatementHandle,
     122             :                             1,
     123          36 :                             NULL);
     124          18 :     if (aErr)
     125             :         SAL_WARN("connectivity.firebird", "isc_dsql_execute failed");
     126             : 
     127          54 :     m_xResultSet = new OResultSet(m_pConnection.get(),
     128             :                                   m_aMutex,
     129             :                                   uno::Reference< XInterface >(*this),
     130             :                                   m_aStatementHandle,
     131          36 :                                   m_pSqlda);
     132             : 
     133             :     // TODO: deal with cleanup
     134             : 
     135          18 :     evaluateStatusVector(m_statusVector, sql, *this);
     136             : 
     137          18 :     if (isDDLStatement())
     138             :     {
     139           0 :         m_pConnection->commit();
     140           0 :         m_pConnection->notifyDatabaseModified();
     141             :     }
     142          18 :     else if (getStatementChangeCount() > 0)
     143             :     {
     144           0 :         m_pConnection->notifyDatabaseModified();
     145             :     }
     146             : 
     147          18 :     return m_xResultSet;
     148             : }
     149             : 
     150           0 : sal_Bool SAL_CALL OStatement::execute(const OUString& sql)
     151             :     throw(SQLException, RuntimeException, std::exception)
     152             : {
     153           0 :     uno::Reference< XResultSet > xResults = executeQuery(sql);
     154           0 :     return xResults.is();
     155             :     // TODO: what if we have multiple results?
     156             : }
     157             : 
     158           0 : uno::Reference< XConnection > SAL_CALL OStatement::getConnection()
     159             :     throw(SQLException, RuntimeException, std::exception)
     160             : {
     161           0 :     MutexGuard aGuard(m_aMutex);
     162           0 :     checkDisposed(OStatementCommonBase_Base::rBHelper.bDisposed);
     163             : 
     164           0 :     return uno::Reference<XConnection>(m_pConnection.get());
     165             : }
     166             : 
     167          72 : Any SAL_CALL OStatement::queryInterface( const Type & rType ) throw(RuntimeException, std::exception)
     168             : {
     169          72 :     Any aRet = OStatement_Base::queryInterface(rType);
     170          72 :     if(!aRet.hasValue())
     171          70 :         aRet = ::cppu::queryInterface(rType,static_cast< XBatchExecution*> (this));
     172          72 :     if(!aRet.hasValue())
     173          70 :         aRet = OStatementCommonBase::queryInterface(rType);
     174          72 :     return aRet;
     175             : }
     176             : 
     177           0 : uno::Sequence< Type > SAL_CALL OStatement::getTypes()
     178             :     throw(RuntimeException, std::exception)
     179             : {
     180             :     return concatSequences(OStatement_Base::getTypes(),
     181           0 :                            OStatementCommonBase::getTypes());
     182             : }
     183             : 
     184          24 : void SAL_CALL OStatement::close() throw(SQLException, RuntimeException, std::exception)
     185             : {
     186          24 :     OStatementCommonBase::close();
     187          24 : }
     188             : 
     189          22 : void SAL_CALL OStatement::disposing()
     190             : {
     191          22 :     disposeResultSet();
     192          22 :     close();
     193          22 : }
     194             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10