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