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

Generated by: LCOV version 1.10