bump product version to 4.1.6.2
[LibreOffice.git] / connectivity / source / drivers / odbcbase / OConnection.cxx
blob9e04bba0428d1fafaed5bc9d871db97188a112df
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
36 #include <string.h>
38 using namespace connectivity::odbc;
39 using namespace connectivity;
40 using namespace dbtools;
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 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 ,m_bReadOnly(sal_True)
61 m_pDriver->acquire();
63 //-----------------------------------------------------------------------------
64 OConnection::~OConnection()
66 if(!isClosed( ))
67 close();
69 if ( SQL_NULL_HANDLE != m_aConnectionHandle )
71 SQLRETURN rc;
73 rc = N3SQLDisconnect( m_aConnectionHandle );
74 OSL_ENSURE( rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO, "Failure from SQLDisconnect" );
76 rc = N3SQLFreeHandle( SQL_HANDLE_DBC, m_aConnectionHandle );
77 OSL_ENSURE( rc == SQL_SUCCESS , "Failure from SQLFreeHandle for connection");
78 (void) rc;
80 m_aConnectionHandle = SQL_NULL_HANDLE;
83 m_pDriver->release();
84 m_pDriver = NULL;
86 //-----------------------------------------------------------------------------
87 void SAL_CALL OConnection::release() throw()
89 relase_ChildImpl();
91 // -----------------------------------------------------------------------------
92 oslGenericFunction OConnection::getOdbcFunction(sal_Int32 _nIndex) const
94 OSL_ENSURE(m_pDriver,"OConnection::getOdbcFunction: m_pDriver is null!");
95 return m_pDriver->getOdbcFunction(_nIndex);
97 //-----------------------------------------------------------------------------
98 SQLRETURN OConnection::OpenConnection(const OUString& aConnectStr,sal_Int32 nTimeOut, sal_Bool bSilent)
100 ::osl::MutexGuard aGuard( m_aMutex );
102 if (m_aConnectionHandle == SQL_NULL_HANDLE)
103 return -1;
105 SQLRETURN nSQLRETURN = 0;
106 SDB_ODBC_CHAR szConnStrOut[4096];
107 SDB_ODBC_CHAR szConnStrIn[2048];
108 SQLSMALLINT cbConnStrOut;
109 memset(szConnStrOut,'\0',4096);
110 memset(szConnStrIn,'\0',2048);
111 OString aConStr(OUStringToOString(aConnectStr,getTextEncoding()));
112 memcpy(szConnStrIn, (SDB_ODBC_CHAR*) aConStr.getStr(), ::std::min<sal_Int32>((sal_Int32)2048,aConStr.getLength()));
114 #ifndef MACOSX
115 N3SQLSetConnectAttr(m_aConnectionHandle,SQL_ATTR_LOGIN_TIMEOUT,(SQLPOINTER)(sal_IntPtr)nTimeOut,SQL_IS_UINTEGER);
116 #else
117 (void)nTimeOut; /* WaE */
118 #endif
120 #ifdef LINUX
121 OSL_UNUSED( bSilent );
122 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 SQL_DRIVER_NOPROMPT);
130 if (nSQLRETURN == SQL_ERROR || nSQLRETURN == SQL_NO_DATA || SQL_SUCCESS_WITH_INFO == nSQLRETURN)
131 return nSQLRETURN;
132 #else
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;
146 m_bClosed = sal_False;
148 #endif //LINUX
152 OUString aVal;
153 OTools::GetInfo(this,m_aConnectionHandle,SQL_DATA_SOURCE_READ_ONLY,aVal,*this,getTextEncoding());
154 m_bReadOnly = !aVal.compareToAscii("Y");
156 catch(Exception&)
158 m_bReadOnly = sal_True;
162 OUString sVersion;
163 OTools::GetInfo(this,m_aConnectionHandle,SQL_DRIVER_ODBC_VER,sVersion,*this,getTextEncoding());
164 m_bUseOldDateFormat = sVersion == OUString("02.50") || sVersion == OUString("02.00");
166 catch(Exception&)
171 // autocoomit is always default
173 if (!m_bReadOnly)
174 N3SQLSetConnectAttr(m_aConnectionHandle,SQL_ATTR_AUTOCOMMIT,(SQLPOINTER)SQL_AUTOCOMMIT_ON,SQL_IS_INTEGER);
176 return nSQLRETURN;
178 //-----------------------------------------------------------------------------
179 SQLRETURN OConnection::Construct(const OUString& url,const Sequence< PropertyValue >& info) throw(SQLException)
181 m_aConnectionHandle = SQL_NULL_HANDLE;
182 m_sURL = url;
183 setConnectionInfo(info);
185 N3SQLAllocHandle(SQL_HANDLE_DBC,m_pDriverHandleCopy,&m_aConnectionHandle);
186 if(m_aConnectionHandle == SQL_NULL_HANDLE)
187 throw SQLException();
189 sal_Int32 nLen = url.indexOf(':');
190 nLen = url.indexOf(':',nLen+1);
191 OUString aDSN("DSN="), aUID, aPWD, aSysDrvSettings;
192 aDSN += url.copy(nLen+1);
194 const char* pUser = "user";
195 const char* pTimeout = "Timeout";
196 const char* pSilent = "Silent";
197 const char* pPwd = "password";
198 const char* pUseCatalog = "UseCatalog";
199 const char* pSysDrv = "SystemDriverSettings";
200 const char* pCharSet = "CharSet";
201 const char* pParaName = "ParameterNameSubstitution";
202 const char* pPrivName = "IgnoreDriverPrivileges";
203 const char* pVerColName = "PreventGetVersionColumns"; // #i60273#
204 const char* pRetrieving = "IsAutoRetrievingEnabled";
205 const char* pRetriStmt = "AutoRetrievingStatement";
207 sal_Int32 nTimeout = 20;
208 sal_Bool bSilent = sal_True;
209 const PropertyValue *pBegin = info.getConstArray();
210 const PropertyValue *pEnd = pBegin + info.getLength();
211 for(;pBegin != pEnd;++pBegin)
213 if(!pBegin->Name.compareToAscii(pTimeout))
214 OSL_VERIFY( pBegin->Value >>= nTimeout );
215 else if(!pBegin->Name.compareToAscii(pSilent))
216 OSL_VERIFY( pBegin->Value >>= bSilent );
217 else if(!pBegin->Name.compareToAscii(pPrivName))
218 OSL_VERIFY( pBegin->Value >>= m_bIgnoreDriverPrivileges );
219 else if(!pBegin->Name.compareToAscii(pVerColName))
220 OSL_VERIFY( pBegin->Value >>= m_bPreventGetVersionColumns );
221 else if(!pBegin->Name.compareToAscii(pParaName))
222 OSL_VERIFY( pBegin->Value >>= m_bParameterSubstitution );
223 else if(!pBegin->Name.compareToAscii(pRetrieving))
225 sal_Bool bAutoRetrievingEnabled = sal_False;
226 OSL_VERIFY( pBegin->Value >>= bAutoRetrievingEnabled );
227 enableAutoRetrievingEnabled(bAutoRetrievingEnabled);
229 else if(!pBegin->Name.compareToAscii(pRetriStmt))
231 OUString sGeneratedValueStatement;
232 OSL_VERIFY( pBegin->Value >>= sGeneratedValueStatement );
233 setAutoRetrievingStatement(sGeneratedValueStatement);
235 else if(!pBegin->Name.compareToAscii(pUser))
237 OSL_VERIFY( pBegin->Value >>= aUID );
238 aDSN = aDSN + OUString(";UID=") + aUID;
240 else if(!pBegin->Name.compareToAscii(pPwd))
242 OSL_VERIFY( pBegin->Value >>= aPWD );
243 aDSN = aDSN + OUString(";PWD=") + aPWD;
245 else if(!pBegin->Name.compareToAscii(pUseCatalog))
247 OSL_VERIFY( pBegin->Value >>= m_bUseCatalog );
249 else if(!pBegin->Name.compareToAscii(pSysDrv))
251 OSL_VERIFY( pBegin->Value >>= aSysDrvSettings );
252 aDSN += OUString(";");
253 aDSN += aSysDrvSettings;
255 else if(0 == pBegin->Name.compareToAscii(pCharSet))
257 OUString sIanaName;
258 OSL_VERIFY( pBegin->Value >>= sIanaName );
260 ::dbtools::OCharsetMap aLookupIanaName;
261 ::dbtools::OCharsetMap::const_iterator aLookup = aLookupIanaName.find(sIanaName, ::dbtools::OCharsetMap::IANA());
262 if (aLookup != aLookupIanaName.end())
263 m_nTextEncoding = (*aLookup).getEncoding();
264 else
265 m_nTextEncoding = RTL_TEXTENCODING_DONTKNOW;
266 if(m_nTextEncoding == RTL_TEXTENCODING_DONTKNOW)
267 m_nTextEncoding = osl_getThreadTextEncoding();
270 m_sUser = aUID;
272 SQLRETURN nSQLRETURN = OpenConnection(aDSN,nTimeout, bSilent);
273 if (nSQLRETURN == SQL_ERROR || nSQLRETURN == SQL_NO_DATA)
275 OTools::ThrowException(this,nSQLRETURN,m_aConnectionHandle,SQL_HANDLE_DBC,*this,sal_False);
277 return nSQLRETURN;
279 // XServiceInfo
280 // --------------------------------------------------------------------------------
281 IMPLEMENT_SERVICE_INFO(OConnection, "com.sun.star.sdbc.drivers.odbc.OConnection", "com.sun.star.sdbc.Connection")
283 // --------------------------------------------------------------------------------
284 Reference< XStatement > SAL_CALL OConnection::createStatement( ) throw(SQLException, RuntimeException)
286 ::osl::MutexGuard aGuard( m_aMutex );
287 checkDisposed(OConnection_BASE::rBHelper.bDisposed);
289 Reference< XStatement > xReturn = new OStatement(this);
290 m_aStatements.push_back(WeakReferenceHelper(xReturn));
291 return xReturn;
293 // --------------------------------------------------------------------------------
294 Reference< XPreparedStatement > SAL_CALL OConnection::prepareStatement( const OUString& sql ) throw(SQLException, RuntimeException)
296 ::osl::MutexGuard aGuard( m_aMutex );
297 checkDisposed(OConnection_BASE::rBHelper.bDisposed);
299 Reference< XPreparedStatement > xReturn = new OPreparedStatement(this,sql);
300 m_aStatements.push_back(WeakReferenceHelper(xReturn));
301 return xReturn;
303 // --------------------------------------------------------------------------------
304 Reference< XPreparedStatement > SAL_CALL OConnection::prepareCall( const OUString& /*sql*/ ) throw(SQLException, RuntimeException)
306 ::dbtools::throwFeatureNotImplementedException( "XConnection::prepareCall", *this );
307 return NULL;
309 // --------------------------------------------------------------------------------
310 OUString SAL_CALL OConnection::nativeSQL( const OUString& sql ) throw(SQLException, RuntimeException)
312 ::osl::MutexGuard aGuard( m_aMutex );
314 OString aSql(OUStringToOString(sql.getStr(),getTextEncoding()));
315 char pOut[2048];
316 SQLINTEGER nOutLen;
317 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 return OUString(pOut,nOutLen,getTextEncoding());
320 // --------------------------------------------------------------------------------
321 void SAL_CALL OConnection::setAutoCommit( sal_Bool autoCommit ) throw(SQLException, RuntimeException)
323 ::osl::MutexGuard aGuard( m_aMutex );
324 checkDisposed(OConnection_BASE::rBHelper.bDisposed);
327 OTools::ThrowException(this,N3SQLSetConnectAttr(m_aConnectionHandle,
328 SQL_ATTR_AUTOCOMMIT,
329 (SQLPOINTER)((autoCommit) ? SQL_AUTOCOMMIT_ON : SQL_AUTOCOMMIT_OFF) ,SQL_IS_INTEGER),
330 m_aConnectionHandle,SQL_HANDLE_DBC,*this);
332 // --------------------------------------------------------------------------------
333 sal_Bool SAL_CALL OConnection::getAutoCommit( ) throw(SQLException, RuntimeException)
335 ::osl::MutexGuard aGuard( m_aMutex );
336 checkDisposed(OConnection_BASE::rBHelper.bDisposed);
339 sal_uInt32 nOption = 0;
340 OTools::ThrowException(this,N3SQLGetConnectAttr(m_aConnectionHandle,
341 SQL_ATTR_AUTOCOMMIT, &nOption,0,0),m_aConnectionHandle,SQL_HANDLE_DBC,*this);
342 return nOption == SQL_AUTOCOMMIT_ON ;
344 // --------------------------------------------------------------------------------
345 void SAL_CALL OConnection::commit( ) throw(SQLException, RuntimeException)
347 ::osl::MutexGuard aGuard( m_aMutex );
348 checkDisposed(OConnection_BASE::rBHelper.bDisposed);
351 OTools::ThrowException(this,N3SQLEndTran(SQL_HANDLE_DBC,m_aConnectionHandle,SQL_COMMIT),m_aConnectionHandle,SQL_HANDLE_DBC,*this);
353 // --------------------------------------------------------------------------------
354 void SAL_CALL OConnection::rollback( ) throw(SQLException, RuntimeException)
356 ::osl::MutexGuard aGuard( m_aMutex );
357 checkDisposed(OConnection_BASE::rBHelper.bDisposed);
360 OTools::ThrowException(this,N3SQLEndTran(SQL_HANDLE_DBC,m_aConnectionHandle,SQL_ROLLBACK),m_aConnectionHandle,SQL_HANDLE_DBC,*this);
362 // --------------------------------------------------------------------------------
363 sal_Bool SAL_CALL OConnection::isClosed( ) throw(SQLException, RuntimeException)
365 ::osl::MutexGuard aGuard( m_aMutex );
367 return OConnection_BASE::rBHelper.bDisposed;
369 // --------------------------------------------------------------------------------
370 Reference< XDatabaseMetaData > SAL_CALL OConnection::getMetaData( ) throw(SQLException, RuntimeException)
372 ::osl::MutexGuard aGuard( m_aMutex );
373 checkDisposed(OConnection_BASE::rBHelper.bDisposed);
375 Reference< XDatabaseMetaData > xMetaData = m_xMetaData;
376 if(!xMetaData.is())
378 xMetaData = new ODatabaseMetaData(m_aConnectionHandle,this);
379 m_xMetaData = xMetaData;
382 return xMetaData;
384 // --------------------------------------------------------------------------------
385 void SAL_CALL OConnection::setReadOnly( sal_Bool readOnly ) throw(SQLException, RuntimeException)
387 ::osl::MutexGuard aGuard( m_aMutex );
388 checkDisposed(OConnection_BASE::rBHelper.bDisposed);
391 OTools::ThrowException(this,
392 N3SQLSetConnectAttr(m_aConnectionHandle,SQL_ATTR_ACCESS_MODE,reinterpret_cast< SQLPOINTER >( readOnly ),SQL_IS_INTEGER),
393 m_aConnectionHandle,SQL_HANDLE_DBC,*this);
395 // --------------------------------------------------------------------------------
396 sal_Bool SAL_CALL OConnection::isReadOnly() throw(SQLException, RuntimeException)
398 // const member which will initialized only once
399 return m_bReadOnly;
401 // --------------------------------------------------------------------------------
402 void SAL_CALL OConnection::setCatalog( const OUString& catalog ) throw(SQLException, RuntimeException)
404 ::osl::MutexGuard aGuard( m_aMutex );
405 checkDisposed(OConnection_BASE::rBHelper.bDisposed);
408 OString aCat(OUStringToOString(catalog.getStr(),getTextEncoding()));
409 OTools::ThrowException(this,
410 N3SQLSetConnectAttr(m_aConnectionHandle,SQL_ATTR_CURRENT_CATALOG,(SDB_ODBC_CHAR*)aCat.getStr(),SQL_NTS),
411 m_aConnectionHandle,SQL_HANDLE_DBC,*this);
413 // --------------------------------------------------------------------------------
414 OUString SAL_CALL OConnection::getCatalog( ) throw(SQLException, RuntimeException)
416 ::osl::MutexGuard aGuard( m_aMutex );
417 checkDisposed(OConnection_BASE::rBHelper.bDisposed);
420 SQLINTEGER nValueLen;
421 char pCat[1024];
422 OTools::ThrowException(this,
423 N3SQLGetConnectAttr(m_aConnectionHandle,SQL_ATTR_CURRENT_CATALOG,(SDB_ODBC_CHAR*)pCat,(sizeof pCat)-1,&nValueLen),
424 m_aConnectionHandle,SQL_HANDLE_DBC,*this);
426 return OUString(pCat,nValueLen,getTextEncoding());
428 // --------------------------------------------------------------------------------
429 void SAL_CALL OConnection::setTransactionIsolation( sal_Int32 level ) throw(SQLException, RuntimeException)
431 ::osl::MutexGuard aGuard( m_aMutex );
432 checkDisposed(OConnection_BASE::rBHelper.bDisposed);
435 OTools::ThrowException(this,N3SQLSetConnectAttr(m_aConnectionHandle,
436 SQL_ATTR_TXN_ISOLATION,
437 (SQLPOINTER)(sal_IntPtr)level,SQL_IS_INTEGER),
438 m_aConnectionHandle,SQL_HANDLE_DBC,*this);
440 // --------------------------------------------------------------------------------
441 sal_Int32 SAL_CALL OConnection::getTransactionIsolation( ) throw(SQLException, RuntimeException)
443 ::osl::MutexGuard aGuard( m_aMutex );
444 checkDisposed(OConnection_BASE::rBHelper.bDisposed);
447 sal_Int32 nTxn = 0;
448 SQLINTEGER nValueLen;
449 OTools::ThrowException(this,
450 N3SQLGetConnectAttr(m_aConnectionHandle,SQL_ATTR_TXN_ISOLATION,&nTxn,sizeof nTxn,&nValueLen),
451 m_aConnectionHandle,SQL_HANDLE_DBC,*this);
452 return nTxn;
454 // --------------------------------------------------------------------------------
455 Reference< ::com::sun::star::container::XNameAccess > SAL_CALL OConnection::getTypeMap( ) throw(SQLException, RuntimeException)
457 ::osl::MutexGuard aGuard( m_aMutex );
458 checkDisposed(OConnection_BASE::rBHelper.bDisposed);
461 return NULL;
463 // --------------------------------------------------------------------------------
464 void SAL_CALL OConnection::setTypeMap( const Reference< ::com::sun::star::container::XNameAccess >& /*typeMap*/ ) throw(SQLException, RuntimeException)
466 ::dbtools::throwFeatureNotImplementedException( "XConnection::setTypeMap", *this );
468 // --------------------------------------------------------------------------------
469 // XCloseable
470 void SAL_CALL OConnection::close( ) throw(SQLException, RuntimeException)
473 ::osl::MutexGuard aGuard( m_aMutex );
474 checkDisposed(OConnection_BASE::rBHelper.bDisposed);
477 dispose();
479 // --------------------------------------------------------------------------------
480 // XWarningsSupplier
481 Any SAL_CALL OConnection::getWarnings( ) throw(SQLException, RuntimeException)
483 return Any();
485 // --------------------------------------------------------------------------------
486 void SAL_CALL OConnection::clearWarnings( ) throw(SQLException, RuntimeException)
489 //------------------------------------------------------------------------------
490 void OConnection::disposing()
492 ::osl::MutexGuard aGuard(m_aMutex);
494 OConnection_BASE::disposing();
496 for (::std::map< SQLHANDLE,OConnection*>::iterator aConIter = m_aConnections.begin();aConIter != m_aConnections.end();++aConIter )
497 aConIter->second->dispose();
499 ::std::map< SQLHANDLE,OConnection*>().swap(m_aConnections);
501 if(!m_bClosed)
502 N3SQLDisconnect(m_aConnectionHandle);
503 m_bClosed = sal_True;
505 dispose_ChildImpl();
507 // -----------------------------------------------------------------------------
508 OConnection* OConnection::cloneConnection()
510 return new OConnection(m_pDriverHandleCopy,m_pDriver);
512 // -----------------------------------------------------------------------------
513 SQLHANDLE OConnection::createStatementHandle()
515 OConnection* pConnectionTemp = this;
516 sal_Bool bNew = sal_False;
519 sal_Int32 nMaxStatements = getMetaData()->getMaxStatements();
520 if(nMaxStatements && nMaxStatements <= m_nStatementCount)
522 OConnection* pConnection = cloneConnection();
523 pConnection->acquire();
524 pConnection->Construct(m_sURL,getConnectionInfo());
525 pConnectionTemp = pConnection;
526 bNew = sal_True;
529 catch(SQLException&)
533 SQLHANDLE aStatementHandle = SQL_NULL_HANDLE;
534 SQLRETURN nRetcode = N3SQLAllocHandle(SQL_HANDLE_STMT,pConnectionTemp->getConnection(),&aStatementHandle);
535 OSL_UNUSED( nRetcode );
536 ++m_nStatementCount;
537 if(bNew)
538 m_aConnections.insert(::std::map< SQLHANDLE,OConnection*>::value_type(aStatementHandle,pConnectionTemp));
540 return aStatementHandle;
543 // -----------------------------------------------------------------------------
544 void OConnection::freeStatementHandle(SQLHANDLE& _pHandle)
546 if( SQL_NULL_HANDLE == _pHandle )
547 return;
549 ::std::map< SQLHANDLE,OConnection*>::iterator aFind = m_aConnections.find(_pHandle);
551 N3SQLFreeStmt(_pHandle,SQL_RESET_PARAMS);
552 N3SQLFreeStmt(_pHandle,SQL_UNBIND);
553 N3SQLFreeStmt(_pHandle,SQL_CLOSE);
554 N3SQLFreeHandle(SQL_HANDLE_STMT,_pHandle);
556 _pHandle = SQL_NULL_HANDLE;
558 if(aFind != m_aConnections.end())
560 aFind->second->dispose();
561 m_aConnections.erase(aFind);
563 --m_nStatementCount;
565 // -----------------------------------------------------------------------------
569 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */