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