LCOV - code coverage report
Current view: top level - libreoffice/connectivity/source/drivers/odbcbase - OConnection.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 266 0.0 %
Date: 2012-12-27 Functions: 0 35 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 "odbc/OTools.hxx"
      21             : #include "odbc/OConnection.hxx"
      22             : #include "odbc/ODatabaseMetaData.hxx"
      23             : #include "odbc/OFunctions.hxx"
      24             : #include "odbc/ODriver.hxx"
      25             : #include "odbc/OStatement.hxx"
      26             : #include "odbc/OPreparedStatement.hxx"
      27             : #include <com/sun/star/sdbc/ColumnValue.hpp>
      28             : #include <com/sun/star/sdbc/XRow.hpp>
      29             : #include <com/sun/star/lang/DisposedException.hpp>
      30             : #include <connectivity/dbcharset.hxx>
      31             : #include <connectivity/FValue.hxx>
      32             : #include <comphelper/extract.hxx>
      33             : #include "diagnose_ex.h"
      34             : #include <connectivity/dbexception.hxx>
      35             : 
      36             : #include <string.h>
      37             : 
      38             : using namespace connectivity::odbc;
      39             : using namespace connectivity;
      40             : using namespace dbtools;
      41             : 
      42             : //------------------------------------------------------------------------------
      43             : using namespace com::sun::star::uno;
      44             : using namespace com::sun::star::lang;
      45             : using namespace com::sun::star::beans;
      46             : using namespace com::sun::star::sdbc;
      47             : // --------------------------------------------------------------------------------
      48           0 : OConnection::OConnection(const SQLHANDLE _pDriverHandle,ODBCDriver* _pDriver)
      49             :                          : OSubComponent<OConnection, OConnection_BASE>((::cppu::OWeakObject*)_pDriver, this)
      50             :                          ,m_pDriver(_pDriver)
      51             :                          ,m_pDriverHandleCopy(_pDriverHandle)
      52             :                          ,m_nStatementCount(0)
      53             :                          ,m_bClosed(sal_True)
      54             :                          ,m_bUseCatalog(sal_False)
      55             :                          ,m_bUseOldDateFormat(sal_False)
      56             :                          ,m_bParameterSubstitution(sal_False)
      57             :                          ,m_bIgnoreDriverPrivileges(sal_False)
      58             :                          ,m_bPreventGetVersionColumns(sal_False)
      59           0 :                          ,m_bReadOnly(sal_True)
      60             : {
      61           0 :     m_pDriver->acquire();
      62           0 : }
      63             : //-----------------------------------------------------------------------------
      64           0 : OConnection::~OConnection()
      65             : {
      66           0 :     if(!isClosed(  ))
      67           0 :         close();
      68             : 
      69           0 :     if ( SQL_NULL_HANDLE != m_aConnectionHandle )
      70             :     {
      71             :         SQLRETURN rc;
      72             : 
      73           0 :         rc = N3SQLDisconnect( m_aConnectionHandle );
      74             :         OSL_ENSURE( rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO, "Failure from SQLDisconnect" );
      75             : 
      76           0 :         rc = N3SQLFreeHandle( SQL_HANDLE_DBC, m_aConnectionHandle );
      77             :         OSL_ENSURE( rc == SQL_SUCCESS , "Failure from SQLFreeHandle for connection");
      78             :         (void) rc;
      79             : 
      80           0 :         m_aConnectionHandle = SQL_NULL_HANDLE;
      81             :     }
      82             : 
      83           0 :     m_pDriver->release();
      84           0 :     m_pDriver = NULL;
      85           0 : }
      86             : //-----------------------------------------------------------------------------
      87           0 : void SAL_CALL OConnection::release() throw()
      88             : {
      89           0 :     relase_ChildImpl();
      90           0 : }
      91             : // -----------------------------------------------------------------------------
      92           0 : oslGenericFunction OConnection::getOdbcFunction(sal_Int32 _nIndex)  const
      93             : {
      94             :     OSL_ENSURE(m_pDriver,"OConnection::getOdbcFunction: m_pDriver is null!");
      95           0 :     return m_pDriver->getOdbcFunction(_nIndex);
      96             : }
      97             : //-----------------------------------------------------------------------------
      98           0 : SQLRETURN OConnection::OpenConnection(const ::rtl::OUString& aConnectStr,sal_Int32 nTimeOut, sal_Bool bSilent)
      99             : {
     100           0 :     ::osl::MutexGuard aGuard( m_aMutex );
     101             : 
     102           0 :     if (m_aConnectionHandle == SQL_NULL_HANDLE)
     103           0 :         return -1;
     104             : 
     105           0 :     SQLRETURN nSQLRETURN = 0;
     106             :     SDB_ODBC_CHAR szConnStrOut[4096];
     107             :     SDB_ODBC_CHAR szConnStrIn[2048];
     108             :     SQLSMALLINT cbConnStrOut;
     109           0 :     memset(szConnStrOut,'\0',4096);
     110           0 :     memset(szConnStrIn,'\0',2048);
     111           0 :     ::rtl::OString aConStr(::rtl::OUStringToOString(aConnectStr,getTextEncoding()));
     112           0 :     memcpy(szConnStrIn, (SDB_ODBC_CHAR*) aConStr.getStr(), ::std::min<sal_Int32>((sal_Int32)2048,aConStr.getLength()));
     113             : 
     114             : #ifndef MACOSX
     115           0 :     N3SQLSetConnectAttr(m_aConnectionHandle,SQL_ATTR_LOGIN_TIMEOUT,(SQLPOINTER)(sal_IntPtr)nTimeOut,SQL_IS_UINTEGER);
     116             : #else
     117             :     (void)nTimeOut; /* WaE */
     118             : #endif
     119             : 
     120             : #ifdef LINUX
     121             :     OSL_UNUSED( bSilent );
     122           0 :     nSQLRETURN = N3SQLDriverConnect(m_aConnectionHandle,
     123             :                       NULL,
     124             :                       szConnStrIn,
     125             :                       (SQLSMALLINT) ::std::min((sal_Int32)2048,aConStr.getLength()),
     126             :                       szConnStrOut,
     127             :                       (SQLSMALLINT) (sizeof(szConnStrOut)/sizeof(SDB_ODBC_CHAR)) -1,
     128             :                       &cbConnStrOut,
     129           0 :                       SQL_DRIVER_NOPROMPT);
     130           0 :     if (nSQLRETURN == SQL_ERROR || nSQLRETURN == SQL_NO_DATA || SQL_SUCCESS_WITH_INFO == nSQLRETURN)
     131           0 :         return nSQLRETURN;
     132             : #else
     133             : 
     134             :     SQLUSMALLINT nSilent =  bSilent ? SQL_DRIVER_NOPROMPT : SQL_DRIVER_COMPLETE;
     135             :     nSQLRETURN = N3SQLDriverConnect(m_aConnectionHandle,
     136             :                       NULL,
     137             :                       szConnStrIn,
     138             :                       (SQLSMALLINT) ::std::min<sal_Int32>((sal_Int32)2048,aConStr.getLength()),
     139             :                       szConnStrOut,
     140             :                       (SQLSMALLINT) sizeof szConnStrOut,
     141             :                       &cbConnStrOut,
     142             :                       nSilent);
     143             :     if (nSQLRETURN == SQL_ERROR || nSQLRETURN == SQL_NO_DATA)
     144             :         return nSQLRETURN;
     145             : 
     146             :     m_bClosed = sal_False;
     147             : 
     148             : #endif //LINUX
     149             : 
     150             :     try
     151             :     {
     152           0 :         ::rtl::OUString aVal;
     153           0 :         OTools::GetInfo(this,m_aConnectionHandle,SQL_DATA_SOURCE_READ_ONLY,aVal,*this,getTextEncoding());
     154           0 :         m_bReadOnly = !aVal.compareToAscii("Y");
     155             :     }
     156           0 :     catch(Exception&)
     157             :     {
     158           0 :         m_bReadOnly = sal_True;
     159             :     }
     160             :     try
     161             :     {
     162           0 :         ::rtl::OUString sVersion;
     163           0 :         OTools::GetInfo(this,m_aConnectionHandle,SQL_DRIVER_ODBC_VER,sVersion,*this,getTextEncoding());
     164           0 :         m_bUseOldDateFormat =  sVersion == ::rtl::OUString("02.50") || sVersion == ::rtl::OUString("02.00");
     165             :     }
     166           0 :     catch(Exception&)
     167             :     {
     168             :     }
     169             : 
     170             : 
     171             :     // autocoomit is always default
     172             : 
     173           0 :     if (!m_bReadOnly)
     174           0 :         N3SQLSetConnectAttr(m_aConnectionHandle,SQL_ATTR_AUTOCOMMIT,(SQLPOINTER)SQL_AUTOCOMMIT_ON,SQL_IS_INTEGER);
     175             : 
     176           0 :     return nSQLRETURN;
     177             : }
     178             : //-----------------------------------------------------------------------------
     179           0 : SQLRETURN OConnection::Construct(const ::rtl::OUString& url,const Sequence< PropertyValue >& info)  throw(SQLException)
     180             : {
     181           0 :     m_aConnectionHandle  = SQL_NULL_HANDLE;
     182           0 :     m_sURL  = url;
     183           0 :     setConnectionInfo(info);
     184             : 
     185           0 :     N3SQLAllocHandle(SQL_HANDLE_DBC,m_pDriverHandleCopy,&m_aConnectionHandle);
     186           0 :     if(m_aConnectionHandle == SQL_NULL_HANDLE)
     187           0 :         throw SQLException();
     188             : 
     189           0 :     sal_Int32 nLen = url.indexOf(':');
     190           0 :     nLen = url.indexOf(':',nLen+1);
     191           0 :     ::rtl::OUString aDSN("DSN="), aUID, aPWD, aSysDrvSettings;
     192           0 :     aDSN += url.copy(nLen+1);
     193             : 
     194           0 :     const char* pUser       = "user";
     195           0 :     const char* pTimeout    = "Timeout";
     196           0 :     const char* pSilent     = "Silent";
     197           0 :     const char* pPwd        = "password";
     198           0 :     const char* pUseCatalog = "UseCatalog";
     199           0 :     const char* pSysDrv     = "SystemDriverSettings";
     200           0 :     const char* pCharSet    = "CharSet";
     201           0 :     const char* pParaName   = "ParameterNameSubstitution";
     202           0 :     const char* pPrivName   = "IgnoreDriverPrivileges";
     203           0 :     const char* pVerColName = "PreventGetVersionColumns";   // #i60273#
     204           0 :     const char* pRetrieving = "IsAutoRetrievingEnabled";
     205           0 :     const char* pRetriStmt  = "AutoRetrievingStatement";
     206             : 
     207           0 :     sal_Int32 nTimeout = 20;
     208           0 :     sal_Bool bSilent = sal_True;
     209           0 :     const PropertyValue *pBegin = info.getConstArray();
     210           0 :     const PropertyValue *pEnd   = pBegin + info.getLength();
     211           0 :     for(;pBegin != pEnd;++pBegin)
     212             :     {
     213           0 :         if(!pBegin->Name.compareToAscii(pTimeout))
     214           0 :             OSL_VERIFY( pBegin->Value >>= nTimeout );
     215           0 :         else if(!pBegin->Name.compareToAscii(pSilent))
     216           0 :             OSL_VERIFY( pBegin->Value >>= bSilent );
     217           0 :         else if(!pBegin->Name.compareToAscii(pPrivName))
     218           0 :             OSL_VERIFY( pBegin->Value >>= m_bIgnoreDriverPrivileges );
     219           0 :         else if(!pBegin->Name.compareToAscii(pVerColName))
     220           0 :             OSL_VERIFY( pBegin->Value >>= m_bPreventGetVersionColumns );
     221           0 :         else if(!pBegin->Name.compareToAscii(pParaName))
     222           0 :             OSL_VERIFY( pBegin->Value >>= m_bParameterSubstitution );
     223           0 :         else if(!pBegin->Name.compareToAscii(pRetrieving))
     224             :         {
     225           0 :             sal_Bool bAutoRetrievingEnabled = sal_False;
     226           0 :             OSL_VERIFY( pBegin->Value >>= bAutoRetrievingEnabled );
     227           0 :             enableAutoRetrievingEnabled(bAutoRetrievingEnabled);
     228             :         }
     229           0 :         else if(!pBegin->Name.compareToAscii(pRetriStmt))
     230             :         {
     231           0 :             ::rtl::OUString sGeneratedValueStatement;
     232           0 :             OSL_VERIFY( pBegin->Value >>= sGeneratedValueStatement );
     233           0 :             setAutoRetrievingStatement(sGeneratedValueStatement);
     234             :         }
     235           0 :         else if(!pBegin->Name.compareToAscii(pUser))
     236             :         {
     237           0 :             OSL_VERIFY( pBegin->Value >>= aUID );
     238           0 :             aDSN = aDSN + ::rtl::OUString(";UID=") + aUID;
     239             :         }
     240           0 :         else if(!pBegin->Name.compareToAscii(pPwd))
     241             :         {
     242           0 :             OSL_VERIFY( pBegin->Value >>= aPWD );
     243           0 :             aDSN = aDSN + ::rtl::OUString(";PWD=") + aPWD;
     244             :         }
     245           0 :         else if(!pBegin->Name.compareToAscii(pUseCatalog))
     246             :         {
     247           0 :              OSL_VERIFY( pBegin->Value >>= m_bUseCatalog );
     248             :         }
     249           0 :         else if(!pBegin->Name.compareToAscii(pSysDrv))
     250             :         {
     251           0 :             OSL_VERIFY( pBegin->Value >>= aSysDrvSettings );
     252           0 :             aDSN += ::rtl::OUString(";");
     253           0 :             aDSN += aSysDrvSettings;
     254             :         }
     255           0 :         else if(0 == pBegin->Name.compareToAscii(pCharSet))
     256             :         {
     257           0 :             ::rtl::OUString sIanaName;
     258           0 :             OSL_VERIFY( pBegin->Value >>= sIanaName );
     259             : 
     260           0 :             ::dbtools::OCharsetMap aLookupIanaName;
     261           0 :             ::dbtools::OCharsetMap::const_iterator aLookup = aLookupIanaName.find(sIanaName, ::dbtools::OCharsetMap::IANA());
     262           0 :             if (aLookup != aLookupIanaName.end())
     263           0 :                 m_nTextEncoding = (*aLookup).getEncoding();
     264             :             else
     265           0 :                 m_nTextEncoding = RTL_TEXTENCODING_DONTKNOW;
     266           0 :             if(m_nTextEncoding == RTL_TEXTENCODING_DONTKNOW)
     267           0 :                 m_nTextEncoding = osl_getThreadTextEncoding();
     268             :         }
     269             :     }
     270           0 :     m_sUser = aUID;
     271             : 
     272           0 :     SQLRETURN nSQLRETURN = OpenConnection(aDSN,nTimeout, bSilent);
     273           0 :     if (nSQLRETURN == SQL_ERROR || nSQLRETURN == SQL_NO_DATA)
     274             :     {
     275           0 :         OTools::ThrowException(this,nSQLRETURN,m_aConnectionHandle,SQL_HANDLE_DBC,*this,sal_False);
     276             :     }
     277           0 :     return nSQLRETURN;
     278             : }
     279             : // XServiceInfo
     280             : // --------------------------------------------------------------------------------
     281           0 : IMPLEMENT_SERVICE_INFO(OConnection, "com.sun.star.sdbc.drivers.odbc.OConnection", "com.sun.star.sdbc.Connection")
     282             : 
     283             : // --------------------------------------------------------------------------------
     284           0 : Reference< XStatement > SAL_CALL OConnection::createStatement(  ) throw(SQLException, RuntimeException)
     285             : {
     286           0 :     ::osl::MutexGuard aGuard( m_aMutex );
     287           0 :     checkDisposed(OConnection_BASE::rBHelper.bDisposed);
     288             : 
     289           0 :     Reference< XStatement > xReturn = new OStatement(this);
     290           0 :     m_aStatements.push_back(WeakReferenceHelper(xReturn));
     291           0 :     return xReturn;
     292             : }
     293             : // --------------------------------------------------------------------------------
     294           0 : Reference< XPreparedStatement > SAL_CALL OConnection::prepareStatement( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException)
     295             : {
     296           0 :     ::osl::MutexGuard aGuard( m_aMutex );
     297           0 :     checkDisposed(OConnection_BASE::rBHelper.bDisposed);
     298             : 
     299           0 :     Reference< XPreparedStatement > xReturn = new OPreparedStatement(this,sql);
     300           0 :     m_aStatements.push_back(WeakReferenceHelper(xReturn));
     301           0 :     return xReturn;
     302             : }
     303             : // --------------------------------------------------------------------------------
     304           0 : Reference< XPreparedStatement > SAL_CALL OConnection::prepareCall( const ::rtl::OUString& /*sql*/ ) throw(SQLException, RuntimeException)
     305             : {
     306           0 :     ::dbtools::throwFeatureNotImplementedException( "XConnection::prepareCall", *this );
     307           0 :     return NULL;
     308             : }
     309             : // --------------------------------------------------------------------------------
     310           0 : ::rtl::OUString SAL_CALL OConnection::nativeSQL( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException)
     311             : {
     312           0 :     ::osl::MutexGuard aGuard( m_aMutex );
     313             : 
     314           0 :     ::rtl::OString aSql(::rtl::OUStringToOString(sql.getStr(),getTextEncoding()));
     315             :     char pOut[2048];
     316             :     SQLINTEGER nOutLen;
     317           0 :     OTools::ThrowException(this,N3SQLNativeSql(m_aConnectionHandle,(SDB_ODBC_CHAR*)aSql.getStr(),aSql.getLength(),(SDB_ODBC_CHAR*)pOut,sizeof pOut - 1,&nOutLen),m_aConnectionHandle,SQL_HANDLE_DBC,*this);
     318           0 :     return ::rtl::OUString(pOut,nOutLen,getTextEncoding());
     319             : }
     320             : // --------------------------------------------------------------------------------
     321           0 : void SAL_CALL OConnection::setAutoCommit( sal_Bool autoCommit ) throw(SQLException, RuntimeException)
     322             : {
     323           0 :     ::osl::MutexGuard aGuard( m_aMutex );
     324           0 :     checkDisposed(OConnection_BASE::rBHelper.bDisposed);
     325             : 
     326             : 
     327           0 :     OTools::ThrowException(this,N3SQLSetConnectAttr(m_aConnectionHandle,
     328             :                                    SQL_ATTR_AUTOCOMMIT,
     329             :                                    (SQLPOINTER)((autoCommit) ? SQL_AUTOCOMMIT_ON : SQL_AUTOCOMMIT_OFF) ,SQL_IS_INTEGER),
     330           0 :                                    m_aConnectionHandle,SQL_HANDLE_DBC,*this);
     331           0 : }
     332             : // --------------------------------------------------------------------------------
     333           0 : sal_Bool SAL_CALL OConnection::getAutoCommit(  ) throw(SQLException, RuntimeException)
     334             : {
     335           0 :     ::osl::MutexGuard aGuard( m_aMutex );
     336           0 :     checkDisposed(OConnection_BASE::rBHelper.bDisposed);
     337             : 
     338             : 
     339           0 :     sal_uInt32 nOption = 0;
     340           0 :     OTools::ThrowException(this,N3SQLGetConnectAttr(m_aConnectionHandle,
     341           0 :                                    SQL_ATTR_AUTOCOMMIT, &nOption,0,0),m_aConnectionHandle,SQL_HANDLE_DBC,*this);
     342           0 :     return nOption == SQL_AUTOCOMMIT_ON ;
     343             : }
     344             : // --------------------------------------------------------------------------------
     345           0 : void SAL_CALL OConnection::commit(  ) throw(SQLException, RuntimeException)
     346             : {
     347           0 :     ::osl::MutexGuard aGuard( m_aMutex );
     348           0 :     checkDisposed(OConnection_BASE::rBHelper.bDisposed);
     349             : 
     350             : 
     351           0 :     OTools::ThrowException(this,N3SQLEndTran(SQL_HANDLE_DBC,m_aConnectionHandle,SQL_COMMIT),m_aConnectionHandle,SQL_HANDLE_DBC,*this);
     352           0 : }
     353             : // --------------------------------------------------------------------------------
     354           0 : void SAL_CALL OConnection::rollback(  ) throw(SQLException, RuntimeException)
     355             : {
     356           0 :     ::osl::MutexGuard aGuard( m_aMutex );
     357           0 :     checkDisposed(OConnection_BASE::rBHelper.bDisposed);
     358             : 
     359             : 
     360           0 :     OTools::ThrowException(this,N3SQLEndTran(SQL_HANDLE_DBC,m_aConnectionHandle,SQL_ROLLBACK),m_aConnectionHandle,SQL_HANDLE_DBC,*this);
     361           0 : }
     362             : // --------------------------------------------------------------------------------
     363           0 : sal_Bool SAL_CALL OConnection::isClosed(  ) throw(SQLException, RuntimeException)
     364             : {
     365           0 :     ::osl::MutexGuard aGuard( m_aMutex );
     366             : 
     367           0 :     return OConnection_BASE::rBHelper.bDisposed;
     368             : }
     369             : // --------------------------------------------------------------------------------
     370           0 : Reference< XDatabaseMetaData > SAL_CALL OConnection::getMetaData(  ) throw(SQLException, RuntimeException)
     371             : {
     372           0 :     ::osl::MutexGuard aGuard( m_aMutex );
     373           0 :     checkDisposed(OConnection_BASE::rBHelper.bDisposed);
     374             : 
     375           0 :     Reference< XDatabaseMetaData > xMetaData = m_xMetaData;
     376           0 :     if(!xMetaData.is())
     377             :     {
     378           0 :         xMetaData = new ODatabaseMetaData(m_aConnectionHandle,this);
     379           0 :         m_xMetaData = xMetaData;
     380             :     }
     381             : 
     382           0 :     return xMetaData;
     383             : }
     384             : // --------------------------------------------------------------------------------
     385           0 : void SAL_CALL OConnection::setReadOnly( sal_Bool readOnly ) throw(SQLException, RuntimeException)
     386             : {
     387           0 :     ::osl::MutexGuard aGuard( m_aMutex );
     388           0 :     checkDisposed(OConnection_BASE::rBHelper.bDisposed);
     389             : 
     390             : 
     391             :     OTools::ThrowException(this,
     392           0 :         N3SQLSetConnectAttr(m_aConnectionHandle,SQL_ATTR_ACCESS_MODE,reinterpret_cast< SQLPOINTER >( readOnly ),SQL_IS_INTEGER),
     393           0 :         m_aConnectionHandle,SQL_HANDLE_DBC,*this);
     394           0 : }
     395             : // --------------------------------------------------------------------------------
     396           0 : sal_Bool SAL_CALL OConnection::isReadOnly() throw(SQLException, RuntimeException)
     397             : {
     398             :     // const member which will initialized only once
     399           0 :     return m_bReadOnly;
     400             : }
     401             : // --------------------------------------------------------------------------------
     402           0 : void SAL_CALL OConnection::setCatalog( const ::rtl::OUString& catalog ) throw(SQLException, RuntimeException)
     403             : {
     404           0 :     ::osl::MutexGuard aGuard( m_aMutex );
     405           0 :     checkDisposed(OConnection_BASE::rBHelper.bDisposed);
     406             : 
     407             : 
     408           0 :     ::rtl::OString aCat(::rtl::OUStringToOString(catalog.getStr(),getTextEncoding()));
     409             :     OTools::ThrowException(this,
     410           0 :         N3SQLSetConnectAttr(m_aConnectionHandle,SQL_ATTR_CURRENT_CATALOG,(SDB_ODBC_CHAR*)aCat.getStr(),SQL_NTS),
     411           0 :         m_aConnectionHandle,SQL_HANDLE_DBC,*this);
     412           0 : }
     413             : // --------------------------------------------------------------------------------
     414           0 : ::rtl::OUString SAL_CALL OConnection::getCatalog(  ) throw(SQLException, RuntimeException)
     415             : {
     416           0 :     ::osl::MutexGuard aGuard( m_aMutex );
     417           0 :     checkDisposed(OConnection_BASE::rBHelper.bDisposed);
     418             : 
     419             : 
     420             :     sal_Int32 nValueLen;
     421             :     char pCat[1024];
     422             :     OTools::ThrowException(this,
     423           0 :         N3SQLGetConnectAttr(m_aConnectionHandle,SQL_ATTR_CURRENT_CATALOG,(SDB_ODBC_CHAR*)pCat,(sizeof pCat)-1,&nValueLen),
     424           0 :         m_aConnectionHandle,SQL_HANDLE_DBC,*this);
     425             : 
     426           0 :     return ::rtl::OUString(pCat,nValueLen,getTextEncoding());
     427             : }
     428             : // --------------------------------------------------------------------------------
     429           0 : void SAL_CALL OConnection::setTransactionIsolation( sal_Int32 level ) throw(SQLException, RuntimeException)
     430             : {
     431           0 :     ::osl::MutexGuard aGuard( m_aMutex );
     432           0 :     checkDisposed(OConnection_BASE::rBHelper.bDisposed);
     433             : 
     434             : 
     435           0 :     OTools::ThrowException(this,N3SQLSetConnectAttr(m_aConnectionHandle,
     436             :                                    SQL_ATTR_TXN_ISOLATION,
     437             :                                    (SQLPOINTER)(sal_IntPtr)level,SQL_IS_INTEGER),
     438           0 :                                    m_aConnectionHandle,SQL_HANDLE_DBC,*this);
     439           0 : }
     440             : // --------------------------------------------------------------------------------
     441           0 : sal_Int32 SAL_CALL OConnection::getTransactionIsolation(  ) throw(SQLException, RuntimeException)
     442             : {
     443           0 :     ::osl::MutexGuard aGuard( m_aMutex );
     444           0 :     checkDisposed(OConnection_BASE::rBHelper.bDisposed);
     445             : 
     446             : 
     447           0 :     sal_Int32 nTxn = 0;
     448             :     SQLINTEGER nValueLen;
     449             :     OTools::ThrowException(this,
     450           0 :         N3SQLGetConnectAttr(m_aConnectionHandle,SQL_ATTR_TXN_ISOLATION,&nTxn,sizeof nTxn,&nValueLen),
     451           0 :         m_aConnectionHandle,SQL_HANDLE_DBC,*this);
     452           0 :     return nTxn;
     453             : }
     454             : // --------------------------------------------------------------------------------
     455           0 : Reference< ::com::sun::star::container::XNameAccess > SAL_CALL OConnection::getTypeMap(  ) throw(SQLException, RuntimeException)
     456             : {
     457           0 :     ::osl::MutexGuard aGuard( m_aMutex );
     458           0 :     checkDisposed(OConnection_BASE::rBHelper.bDisposed);
     459             : 
     460             : 
     461           0 :     return NULL;
     462             : }
     463             : // --------------------------------------------------------------------------------
     464           0 : void SAL_CALL OConnection::setTypeMap( const Reference< ::com::sun::star::container::XNameAccess >& /*typeMap*/ ) throw(SQLException, RuntimeException)
     465             : {
     466           0 :     ::dbtools::throwFeatureNotImplementedException( "XConnection::setTypeMap", *this );
     467           0 : }
     468             : // --------------------------------------------------------------------------------
     469             : // XCloseable
     470           0 : void SAL_CALL OConnection::close(  ) throw(SQLException, RuntimeException)
     471             : {
     472             :     {
     473           0 :         ::osl::MutexGuard aGuard( m_aMutex );
     474           0 :         checkDisposed(OConnection_BASE::rBHelper.bDisposed);
     475             : 
     476             :     }
     477           0 :     dispose();
     478           0 : }
     479             : // --------------------------------------------------------------------------------
     480             : // XWarningsSupplier
     481           0 : Any SAL_CALL OConnection::getWarnings(  ) throw(SQLException, RuntimeException)
     482             : {
     483           0 :     return Any();
     484             : }
     485             : // --------------------------------------------------------------------------------
     486           0 : void SAL_CALL OConnection::clearWarnings(  ) throw(SQLException, RuntimeException)
     487             : {
     488           0 : }
     489             : //------------------------------------------------------------------------------
     490           0 : void OConnection::disposing()
     491             : {
     492           0 :     ::osl::MutexGuard aGuard(m_aMutex);
     493             : 
     494           0 :     OConnection_BASE::disposing();
     495             : 
     496           0 :     for (::std::map< SQLHANDLE,OConnection*>::iterator aConIter = m_aConnections.begin();aConIter != m_aConnections.end();++aConIter )
     497           0 :         aConIter->second->dispose();
     498             : 
     499           0 :     ::std::map< SQLHANDLE,OConnection*>().swap(m_aConnections);
     500             : 
     501           0 :     if(!m_bClosed)
     502           0 :         N3SQLDisconnect(m_aConnectionHandle);
     503           0 :     m_bClosed   = sal_True;
     504             : 
     505           0 :     dispose_ChildImpl();
     506           0 : }
     507             : // -----------------------------------------------------------------------------
     508           0 : OConnection* OConnection::cloneConnection()
     509             : {
     510           0 :     return new OConnection(m_pDriverHandleCopy,m_pDriver);
     511             : }
     512             : // -----------------------------------------------------------------------------
     513           0 : SQLHANDLE OConnection::createStatementHandle()
     514             : {
     515           0 :     OConnection* pConnectionTemp = this;
     516           0 :     sal_Bool bNew = sal_False;
     517             :     try
     518             :     {
     519           0 :         sal_Int32 nMaxStatements = getMetaData()->getMaxStatements();
     520           0 :         if(nMaxStatements && nMaxStatements <= m_nStatementCount)
     521             :         {
     522           0 :             OConnection* pConnection = cloneConnection();
     523           0 :             pConnection->acquire();
     524           0 :             pConnection->Construct(m_sURL,getConnectionInfo());
     525           0 :             pConnectionTemp = pConnection;
     526           0 :             bNew = sal_True;
     527             :         }
     528             :     }
     529           0 :     catch(SQLException&)
     530             :     {
     531             :     }
     532             : 
     533           0 :     SQLHANDLE aStatementHandle = SQL_NULL_HANDLE;
     534           0 :     SQLRETURN nRetcode = N3SQLAllocHandle(SQL_HANDLE_STMT,pConnectionTemp->getConnection(),&aStatementHandle);
     535             :     OSL_UNUSED( nRetcode );
     536           0 :     ++m_nStatementCount;
     537           0 :     if(bNew)
     538           0 :         m_aConnections.insert(::std::map< SQLHANDLE,OConnection*>::value_type(aStatementHandle,pConnectionTemp));
     539             : 
     540           0 :     return aStatementHandle;
     541             : 
     542             : }
     543             : // -----------------------------------------------------------------------------
     544           0 : void OConnection::freeStatementHandle(SQLHANDLE& _pHandle)
     545             : {
     546           0 :     if( SQL_NULL_HANDLE == _pHandle )
     547           0 :         return;
     548             : 
     549           0 :     ::std::map< SQLHANDLE,OConnection*>::iterator aFind = m_aConnections.find(_pHandle);
     550             : 
     551           0 :     N3SQLFreeStmt(_pHandle,SQL_RESET_PARAMS);
     552           0 :     N3SQLFreeStmt(_pHandle,SQL_UNBIND);
     553           0 :     N3SQLFreeStmt(_pHandle,SQL_CLOSE);
     554           0 :     N3SQLFreeHandle(SQL_HANDLE_STMT,_pHandle);
     555             : 
     556           0 :     _pHandle = SQL_NULL_HANDLE;
     557             : 
     558           0 :     if(aFind != m_aConnections.end())
     559             :     {
     560           0 :         aFind->second->dispose();
     561           0 :         m_aConnections.erase(aFind);
     562             :     }
     563           0 :     --m_nStatementCount;
     564             : }
     565             : // -----------------------------------------------------------------------------
     566             : 
     567             : 
     568             : 
     569             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10