xref: /AOO41X/main/connectivity/source/drivers/odbcbase/OConnection.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_connectivity.hxx"
30*cdf0e10cSrcweir #include "odbc/OTools.hxx"
31*cdf0e10cSrcweir #include "odbc/OConnection.hxx"
32*cdf0e10cSrcweir #include "odbc/ODatabaseMetaData.hxx"
33*cdf0e10cSrcweir #include "odbc/OFunctions.hxx"
34*cdf0e10cSrcweir #include "odbc/ODriver.hxx"
35*cdf0e10cSrcweir #include "odbc/OStatement.hxx"
36*cdf0e10cSrcweir #include "odbc/OPreparedStatement.hxx"
37*cdf0e10cSrcweir #include <com/sun/star/sdbc/ColumnValue.hpp>
38*cdf0e10cSrcweir #include <com/sun/star/sdbc/XRow.hpp>
39*cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp>
40*cdf0e10cSrcweir #include <connectivity/dbcharset.hxx>
41*cdf0e10cSrcweir #include <connectivity/FValue.hxx>
42*cdf0e10cSrcweir #include <comphelper/extract.hxx>
43*cdf0e10cSrcweir #include "diagnose_ex.h"
44*cdf0e10cSrcweir #include <connectivity/dbexception.hxx>
45*cdf0e10cSrcweir 
46*cdf0e10cSrcweir #include <string.h>
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir using namespace connectivity::odbc;
49*cdf0e10cSrcweir using namespace connectivity;
50*cdf0e10cSrcweir using namespace dbtools;
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir //------------------------------------------------------------------------------
53*cdf0e10cSrcweir using namespace com::sun::star::uno;
54*cdf0e10cSrcweir using namespace com::sun::star::lang;
55*cdf0e10cSrcweir using namespace com::sun::star::beans;
56*cdf0e10cSrcweir using namespace com::sun::star::sdbc;
57*cdf0e10cSrcweir // --------------------------------------------------------------------------------
58*cdf0e10cSrcweir OConnection::OConnection(const SQLHANDLE _pDriverHandle,ODBCDriver*	_pDriver)
59*cdf0e10cSrcweir 						 : OSubComponent<OConnection, OConnection_BASE>((::cppu::OWeakObject*)_pDriver, this)
60*cdf0e10cSrcweir                          ,m_pDriver(_pDriver)
61*cdf0e10cSrcweir 						 ,m_pDriverHandleCopy(_pDriverHandle)
62*cdf0e10cSrcweir                          ,m_nStatementCount(0)
63*cdf0e10cSrcweir 						 ,m_bClosed(sal_True)
64*cdf0e10cSrcweir                          ,m_bUseCatalog(sal_False)
65*cdf0e10cSrcweir                          ,m_bUseOldDateFormat(sal_False)
66*cdf0e10cSrcweir 						 ,m_bParameterSubstitution(sal_False)
67*cdf0e10cSrcweir 						 ,m_bIgnoreDriverPrivileges(sal_False)
68*cdf0e10cSrcweir                          ,m_bPreventGetVersionColumns(sal_False)
69*cdf0e10cSrcweir                          ,m_bReadOnly(sal_True)
70*cdf0e10cSrcweir {
71*cdf0e10cSrcweir 	m_pDriver->acquire();
72*cdf0e10cSrcweir }
73*cdf0e10cSrcweir //-----------------------------------------------------------------------------
74*cdf0e10cSrcweir OConnection::~OConnection()
75*cdf0e10cSrcweir {
76*cdf0e10cSrcweir 	if(!isClosed(  ))
77*cdf0e10cSrcweir 		close();
78*cdf0e10cSrcweir 
79*cdf0e10cSrcweir 	if ( SQL_NULL_HANDLE != m_aConnectionHandle )
80*cdf0e10cSrcweir 		N3SQLFreeHandle( SQL_HANDLE_DBC, m_aConnectionHandle );
81*cdf0e10cSrcweir 	m_aConnectionHandle = SQL_NULL_HANDLE;
82*cdf0e10cSrcweir 
83*cdf0e10cSrcweir 	m_pDriver->release();
84*cdf0e10cSrcweir 	m_pDriver = NULL;
85*cdf0e10cSrcweir }
86*cdf0e10cSrcweir //-----------------------------------------------------------------------------
87*cdf0e10cSrcweir void SAL_CALL OConnection::release() throw()
88*cdf0e10cSrcweir {
89*cdf0e10cSrcweir 	relase_ChildImpl();
90*cdf0e10cSrcweir }
91*cdf0e10cSrcweir // -----------------------------------------------------------------------------
92*cdf0e10cSrcweir oslGenericFunction OConnection::getOdbcFunction(sal_Int32 _nIndex)  const
93*cdf0e10cSrcweir {
94*cdf0e10cSrcweir 	OSL_ENSURE(m_pDriver,"OConnection::getOdbcFunction: m_pDriver is null!");
95*cdf0e10cSrcweir 	return m_pDriver->getOdbcFunction(_nIndex);
96*cdf0e10cSrcweir }
97*cdf0e10cSrcweir //-----------------------------------------------------------------------------
98*cdf0e10cSrcweir SQLRETURN OConnection::OpenConnection(const ::rtl::OUString& aConnectStr,sal_Int32 nTimeOut, sal_Bool bSilent)
99*cdf0e10cSrcweir {
100*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
101*cdf0e10cSrcweir 
102*cdf0e10cSrcweir 	if (m_aConnectionHandle == SQL_NULL_HANDLE)
103*cdf0e10cSrcweir 		return -1;
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir 	SQLRETURN nSQLRETURN = 0;
106*cdf0e10cSrcweir 	SDB_ODBC_CHAR szConnStrOut[4096];
107*cdf0e10cSrcweir 	SDB_ODBC_CHAR szConnStrIn[2048];
108*cdf0e10cSrcweir 	SQLSMALLINT cbConnStrOut;
109*cdf0e10cSrcweir 	memset(szConnStrOut,'\0',4096);
110*cdf0e10cSrcweir 	memset(szConnStrIn,'\0',2048);
111*cdf0e10cSrcweir 	::rtl::OString aConStr(::rtl::OUStringToOString(aConnectStr,getTextEncoding()));
112*cdf0e10cSrcweir 	memcpy(szConnStrIn, (SDB_ODBC_CHAR*) aConStr.getStr(), ::std::min<sal_Int32>((sal_Int32)2048,aConStr.getLength()));
113*cdf0e10cSrcweir 
114*cdf0e10cSrcweir #ifndef MACOSX
115*cdf0e10cSrcweir 	N3SQLSetConnectAttr(m_aConnectionHandle,SQL_ATTR_LOGIN_TIMEOUT,(SQLPOINTER)nTimeOut,SQL_IS_UINTEGER);
116*cdf0e10cSrcweir 	// Verbindung aufbauen
117*cdf0e10cSrcweir #endif
118*cdf0e10cSrcweir 
119*cdf0e10cSrcweir #ifdef LINUX
120*cdf0e10cSrcweir     OSL_UNUSED( bSilent );
121*cdf0e10cSrcweir 	nSQLRETURN = N3SQLDriverConnect(m_aConnectionHandle,
122*cdf0e10cSrcweir 					  NULL,
123*cdf0e10cSrcweir 					  szConnStrIn,
124*cdf0e10cSrcweir 					  (SQLSMALLINT) ::std::min((sal_Int32)2048,aConStr.getLength()),
125*cdf0e10cSrcweir 					  szConnStrOut,
126*cdf0e10cSrcweir 					  (SQLSMALLINT) (sizeof(szConnStrOut)/sizeof(SDB_ODBC_CHAR)) -1,
127*cdf0e10cSrcweir 					  &cbConnStrOut,
128*cdf0e10cSrcweir 					  SQL_DRIVER_NOPROMPT);
129*cdf0e10cSrcweir 	if (nSQLRETURN == SQL_ERROR || nSQLRETURN == SQL_NO_DATA || SQL_SUCCESS_WITH_INFO == nSQLRETURN)
130*cdf0e10cSrcweir 		return nSQLRETURN;
131*cdf0e10cSrcweir #else
132*cdf0e10cSrcweir 
133*cdf0e10cSrcweir 	SQLUSMALLINT nSilent =  bSilent ? SQL_DRIVER_NOPROMPT : SQL_DRIVER_COMPLETE;
134*cdf0e10cSrcweir 	nSQLRETURN = N3SQLDriverConnect(m_aConnectionHandle,
135*cdf0e10cSrcweir 					  NULL,
136*cdf0e10cSrcweir 					  szConnStrIn,
137*cdf0e10cSrcweir 					  (SQLSMALLINT) ::std::min<sal_Int32>((sal_Int32)2048,aConStr.getLength()),
138*cdf0e10cSrcweir 					  szConnStrOut,
139*cdf0e10cSrcweir 					  (SQLSMALLINT) sizeof szConnStrOut,
140*cdf0e10cSrcweir 					  &cbConnStrOut,
141*cdf0e10cSrcweir 					  nSilent);
142*cdf0e10cSrcweir 	if (nSQLRETURN == SQL_ERROR || nSQLRETURN == SQL_NO_DATA)
143*cdf0e10cSrcweir 		return nSQLRETURN;
144*cdf0e10cSrcweir 
145*cdf0e10cSrcweir 	m_bClosed = sal_False;
146*cdf0e10cSrcweir 
147*cdf0e10cSrcweir #endif //LINUX
148*cdf0e10cSrcweir 
149*cdf0e10cSrcweir 	try
150*cdf0e10cSrcweir 	{
151*cdf0e10cSrcweir 		::rtl::OUString aVal;
152*cdf0e10cSrcweir 		OTools::GetInfo(this,m_aConnectionHandle,SQL_DATA_SOURCE_READ_ONLY,aVal,*this,getTextEncoding());
153*cdf0e10cSrcweir 		m_bReadOnly = !aVal.compareToAscii("Y");
154*cdf0e10cSrcweir 	}
155*cdf0e10cSrcweir 	catch(Exception&)
156*cdf0e10cSrcweir 	{
157*cdf0e10cSrcweir 		m_bReadOnly = sal_True;
158*cdf0e10cSrcweir 	}
159*cdf0e10cSrcweir 	try
160*cdf0e10cSrcweir 	{
161*cdf0e10cSrcweir 		::rtl::OUString sVersion;
162*cdf0e10cSrcweir 		OTools::GetInfo(this,m_aConnectionHandle,SQL_DRIVER_ODBC_VER,sVersion,*this,getTextEncoding());
163*cdf0e10cSrcweir 		m_bUseOldDateFormat	=  sVersion == ::rtl::OUString::createFromAscii("02.50") || sVersion == ::rtl::OUString::createFromAscii("02.00");
164*cdf0e10cSrcweir 	}
165*cdf0e10cSrcweir 	catch(Exception&)
166*cdf0e10cSrcweir 	{
167*cdf0e10cSrcweir 	}
168*cdf0e10cSrcweir 
169*cdf0e10cSrcweir 
170*cdf0e10cSrcweir 	// autocoomit ist immer default
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir 	if (!m_bReadOnly)
173*cdf0e10cSrcweir 		N3SQLSetConnectAttr(m_aConnectionHandle,SQL_ATTR_AUTOCOMMIT,(SQLPOINTER)SQL_AUTOCOMMIT_ON,SQL_IS_INTEGER);
174*cdf0e10cSrcweir 
175*cdf0e10cSrcweir 	return nSQLRETURN;
176*cdf0e10cSrcweir }
177*cdf0e10cSrcweir //-----------------------------------------------------------------------------
178*cdf0e10cSrcweir SQLRETURN OConnection::Construct(const ::rtl::OUString& url,const Sequence< PropertyValue >& info)  throw(SQLException)
179*cdf0e10cSrcweir {
180*cdf0e10cSrcweir 	m_aConnectionHandle  = SQL_NULL_HANDLE;
181*cdf0e10cSrcweir 	m_sURL	= url;
182*cdf0e10cSrcweir 	setConnectionInfo(info);
183*cdf0e10cSrcweir 
184*cdf0e10cSrcweir 	// Connection allozieren
185*cdf0e10cSrcweir 	N3SQLAllocHandle(SQL_HANDLE_DBC,m_pDriverHandleCopy,&m_aConnectionHandle);
186*cdf0e10cSrcweir 	if(m_aConnectionHandle == SQL_NULL_HANDLE)
187*cdf0e10cSrcweir 		throw SQLException();
188*cdf0e10cSrcweir 
189*cdf0e10cSrcweir 	sal_Int32 nLen = url.indexOf(':');
190*cdf0e10cSrcweir 	nLen = url.indexOf(':',nLen+1);
191*cdf0e10cSrcweir 	::rtl::OUString aDSN(RTL_CONSTASCII_USTRINGPARAM("DSN=")), aUID, aPWD, aSysDrvSettings;
192*cdf0e10cSrcweir 	aDSN += url.copy(nLen+1);
193*cdf0e10cSrcweir 
194*cdf0e10cSrcweir 	const char* pUser		= "user";
195*cdf0e10cSrcweir 	const char* pTimeout	= "Timeout";
196*cdf0e10cSrcweir 	const char* pSilent		= "Silent";
197*cdf0e10cSrcweir 	const char* pPwd		= "password";
198*cdf0e10cSrcweir 	const char* pUseCatalog = "UseCatalog";
199*cdf0e10cSrcweir 	const char* pSysDrv		= "SystemDriverSettings";
200*cdf0e10cSrcweir 	const char* pCharSet	= "CharSet";
201*cdf0e10cSrcweir 	const char* pParaName	= "ParameterNameSubstitution";
202*cdf0e10cSrcweir 	const char* pPrivName	= "IgnoreDriverPrivileges";
203*cdf0e10cSrcweir     const char* pVerColName = "PreventGetVersionColumns";   // #i60273#
204*cdf0e10cSrcweir 	const char* pRetrieving	= "IsAutoRetrievingEnabled";
205*cdf0e10cSrcweir 	const char* pRetriStmt	= "AutoRetrievingStatement";
206*cdf0e10cSrcweir 
207*cdf0e10cSrcweir 	sal_Int32 nTimeout = 20;
208*cdf0e10cSrcweir 	sal_Bool bSilent = sal_True;
209*cdf0e10cSrcweir 	const PropertyValue *pBegin	= info.getConstArray();
210*cdf0e10cSrcweir 	const PropertyValue *pEnd	= pBegin + info.getLength();
211*cdf0e10cSrcweir 	for(;pBegin != pEnd;++pBegin)
212*cdf0e10cSrcweir 	{
213*cdf0e10cSrcweir 		if(!pBegin->Name.compareToAscii(pTimeout))
214*cdf0e10cSrcweir 			OSL_VERIFY( pBegin->Value >>= nTimeout );
215*cdf0e10cSrcweir 		else if(!pBegin->Name.compareToAscii(pSilent))
216*cdf0e10cSrcweir 			OSL_VERIFY( pBegin->Value >>= bSilent );
217*cdf0e10cSrcweir 		else if(!pBegin->Name.compareToAscii(pPrivName))
218*cdf0e10cSrcweir 			OSL_VERIFY( pBegin->Value >>= m_bIgnoreDriverPrivileges );
219*cdf0e10cSrcweir         else if(!pBegin->Name.compareToAscii(pVerColName))
220*cdf0e10cSrcweir             OSL_VERIFY( pBegin->Value >>= m_bPreventGetVersionColumns );
221*cdf0e10cSrcweir 		else if(!pBegin->Name.compareToAscii(pParaName))
222*cdf0e10cSrcweir 			OSL_VERIFY( pBegin->Value >>= m_bParameterSubstitution );
223*cdf0e10cSrcweir 		else if(!pBegin->Name.compareToAscii(pRetrieving))
224*cdf0e10cSrcweir 		{
225*cdf0e10cSrcweir 			sal_Bool bAutoRetrievingEnabled = sal_False;
226*cdf0e10cSrcweir 			OSL_VERIFY( pBegin->Value >>= bAutoRetrievingEnabled );
227*cdf0e10cSrcweir 			enableAutoRetrievingEnabled(bAutoRetrievingEnabled);
228*cdf0e10cSrcweir 		}
229*cdf0e10cSrcweir 		else if(!pBegin->Name.compareToAscii(pRetriStmt))
230*cdf0e10cSrcweir 		{
231*cdf0e10cSrcweir 			::rtl::OUString sGeneratedValueStatement;
232*cdf0e10cSrcweir 			OSL_VERIFY( pBegin->Value >>= sGeneratedValueStatement );
233*cdf0e10cSrcweir 			setAutoRetrievingStatement(sGeneratedValueStatement);
234*cdf0e10cSrcweir 		}
235*cdf0e10cSrcweir 		else if(!pBegin->Name.compareToAscii(pUser))
236*cdf0e10cSrcweir 		{
237*cdf0e10cSrcweir 			OSL_VERIFY( pBegin->Value >>= aUID );
238*cdf0e10cSrcweir 			aDSN = aDSN + ::rtl::OUString::createFromAscii(";UID=") + aUID;
239*cdf0e10cSrcweir 		}
240*cdf0e10cSrcweir 		else if(!pBegin->Name.compareToAscii(pPwd))
241*cdf0e10cSrcweir 		{
242*cdf0e10cSrcweir 			OSL_VERIFY( pBegin->Value >>= aPWD );
243*cdf0e10cSrcweir 			aDSN = aDSN + ::rtl::OUString::createFromAscii(";PWD=") + aPWD;
244*cdf0e10cSrcweir 		}
245*cdf0e10cSrcweir 		else if(!pBegin->Name.compareToAscii(pUseCatalog))
246*cdf0e10cSrcweir 		{
247*cdf0e10cSrcweir 			 OSL_VERIFY( pBegin->Value >>= m_bUseCatalog );
248*cdf0e10cSrcweir 		}
249*cdf0e10cSrcweir 		else if(!pBegin->Name.compareToAscii(pSysDrv))
250*cdf0e10cSrcweir 		{
251*cdf0e10cSrcweir 			OSL_VERIFY( pBegin->Value >>= aSysDrvSettings );
252*cdf0e10cSrcweir 			aDSN += ::rtl::OUString::createFromAscii(";");
253*cdf0e10cSrcweir 			aDSN += aSysDrvSettings;
254*cdf0e10cSrcweir 		}
255*cdf0e10cSrcweir 		else if(0 == pBegin->Name.compareToAscii(pCharSet))
256*cdf0e10cSrcweir 		{
257*cdf0e10cSrcweir 			::rtl::OUString sIanaName;
258*cdf0e10cSrcweir 			OSL_VERIFY( pBegin->Value >>= sIanaName );
259*cdf0e10cSrcweir 
260*cdf0e10cSrcweir 			::dbtools::OCharsetMap aLookupIanaName;
261*cdf0e10cSrcweir 			::dbtools::OCharsetMap::const_iterator aLookup = aLookupIanaName.find(sIanaName, ::dbtools::OCharsetMap::IANA());
262*cdf0e10cSrcweir 			if (aLookup != aLookupIanaName.end())
263*cdf0e10cSrcweir 				m_nTextEncoding = (*aLookup).getEncoding();
264*cdf0e10cSrcweir 			else
265*cdf0e10cSrcweir 				m_nTextEncoding = RTL_TEXTENCODING_DONTKNOW;
266*cdf0e10cSrcweir 			if(m_nTextEncoding == RTL_TEXTENCODING_DONTKNOW)
267*cdf0e10cSrcweir 				m_nTextEncoding = osl_getThreadTextEncoding();
268*cdf0e10cSrcweir 		}
269*cdf0e10cSrcweir 	}
270*cdf0e10cSrcweir 	m_sUser = aUID;
271*cdf0e10cSrcweir 
272*cdf0e10cSrcweir 	SQLRETURN nSQLRETURN = OpenConnection(aDSN,nTimeout, bSilent);
273*cdf0e10cSrcweir 	if (nSQLRETURN == SQL_ERROR || nSQLRETURN == SQL_NO_DATA)
274*cdf0e10cSrcweir 	{
275*cdf0e10cSrcweir 		OTools::ThrowException(this,nSQLRETURN,m_aConnectionHandle,SQL_HANDLE_DBC,*this,sal_False);
276*cdf0e10cSrcweir 	}
277*cdf0e10cSrcweir 	return nSQLRETURN;
278*cdf0e10cSrcweir }
279*cdf0e10cSrcweir // XServiceInfo
280*cdf0e10cSrcweir // --------------------------------------------------------------------------------
281*cdf0e10cSrcweir IMPLEMENT_SERVICE_INFO(OConnection, "com.sun.star.sdbc.drivers.odbc.OConnection", "com.sun.star.sdbc.Connection")
282*cdf0e10cSrcweir 
283*cdf0e10cSrcweir // --------------------------------------------------------------------------------
284*cdf0e10cSrcweir Reference< XStatement > SAL_CALL OConnection::createStatement(  ) throw(SQLException, RuntimeException)
285*cdf0e10cSrcweir {
286*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
287*cdf0e10cSrcweir 	checkDisposed(OConnection_BASE::rBHelper.bDisposed);
288*cdf0e10cSrcweir 
289*cdf0e10cSrcweir 	Reference< XStatement > xReturn = new OStatement(this);
290*cdf0e10cSrcweir 	m_aStatements.push_back(WeakReferenceHelper(xReturn));
291*cdf0e10cSrcweir 	return xReturn;
292*cdf0e10cSrcweir }
293*cdf0e10cSrcweir // --------------------------------------------------------------------------------
294*cdf0e10cSrcweir Reference< XPreparedStatement > SAL_CALL OConnection::prepareStatement( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException)
295*cdf0e10cSrcweir {
296*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
297*cdf0e10cSrcweir 	checkDisposed(OConnection_BASE::rBHelper.bDisposed);
298*cdf0e10cSrcweir 
299*cdf0e10cSrcweir 	Reference< XPreparedStatement > xReturn = new OPreparedStatement(this,sql);
300*cdf0e10cSrcweir 	m_aStatements.push_back(WeakReferenceHelper(xReturn));
301*cdf0e10cSrcweir 	return xReturn;
302*cdf0e10cSrcweir }
303*cdf0e10cSrcweir // --------------------------------------------------------------------------------
304*cdf0e10cSrcweir Reference< XPreparedStatement > SAL_CALL OConnection::prepareCall( const ::rtl::OUString& /*sql*/ ) throw(SQLException, RuntimeException)
305*cdf0e10cSrcweir {
306*cdf0e10cSrcweir     ::dbtools::throwFeatureNotImplementedException( "XConnection::prepareCall", *this );
307*cdf0e10cSrcweir     return NULL;
308*cdf0e10cSrcweir }
309*cdf0e10cSrcweir // --------------------------------------------------------------------------------
310*cdf0e10cSrcweir ::rtl::OUString SAL_CALL OConnection::nativeSQL( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException)
311*cdf0e10cSrcweir {
312*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
313*cdf0e10cSrcweir 
314*cdf0e10cSrcweir 	::rtl::OString aSql(::rtl::OUStringToOString(sql.getStr(),getTextEncoding()));
315*cdf0e10cSrcweir 	char pOut[2048];
316*cdf0e10cSrcweir 	SQLINTEGER nOutLen;
317*cdf0e10cSrcweir 	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*cdf0e10cSrcweir 	return ::rtl::OUString(pOut,nOutLen,getTextEncoding());
319*cdf0e10cSrcweir }
320*cdf0e10cSrcweir // --------------------------------------------------------------------------------
321*cdf0e10cSrcweir void SAL_CALL OConnection::setAutoCommit( sal_Bool autoCommit ) throw(SQLException, RuntimeException)
322*cdf0e10cSrcweir {
323*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
324*cdf0e10cSrcweir 	checkDisposed(OConnection_BASE::rBHelper.bDisposed);
325*cdf0e10cSrcweir 
326*cdf0e10cSrcweir 
327*cdf0e10cSrcweir 	OTools::ThrowException(this,N3SQLSetConnectAttr(m_aConnectionHandle,
328*cdf0e10cSrcweir 								   SQL_ATTR_AUTOCOMMIT,
329*cdf0e10cSrcweir 								   (SQLPOINTER)((autoCommit) ? SQL_AUTOCOMMIT_ON : SQL_AUTOCOMMIT_OFF) ,SQL_IS_INTEGER),
330*cdf0e10cSrcweir 								   m_aConnectionHandle,SQL_HANDLE_DBC,*this);
331*cdf0e10cSrcweir }
332*cdf0e10cSrcweir // --------------------------------------------------------------------------------
333*cdf0e10cSrcweir sal_Bool SAL_CALL OConnection::getAutoCommit(  ) throw(SQLException, RuntimeException)
334*cdf0e10cSrcweir {
335*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
336*cdf0e10cSrcweir 	checkDisposed(OConnection_BASE::rBHelper.bDisposed);
337*cdf0e10cSrcweir 
338*cdf0e10cSrcweir 
339*cdf0e10cSrcweir 	sal_uInt32 nOption = 0;
340*cdf0e10cSrcweir 	OTools::ThrowException(this,N3SQLGetConnectAttr(m_aConnectionHandle,
341*cdf0e10cSrcweir 								   SQL_ATTR_AUTOCOMMIT, &nOption,0,0),m_aConnectionHandle,SQL_HANDLE_DBC,*this);
342*cdf0e10cSrcweir 	return nOption == SQL_AUTOCOMMIT_ON ;
343*cdf0e10cSrcweir }
344*cdf0e10cSrcweir // --------------------------------------------------------------------------------
345*cdf0e10cSrcweir void SAL_CALL OConnection::commit(  ) throw(SQLException, RuntimeException)
346*cdf0e10cSrcweir {
347*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
348*cdf0e10cSrcweir 	checkDisposed(OConnection_BASE::rBHelper.bDisposed);
349*cdf0e10cSrcweir 
350*cdf0e10cSrcweir 
351*cdf0e10cSrcweir 	OTools::ThrowException(this,N3SQLEndTran(SQL_HANDLE_DBC,m_aConnectionHandle,SQL_COMMIT),m_aConnectionHandle,SQL_HANDLE_DBC,*this);
352*cdf0e10cSrcweir }
353*cdf0e10cSrcweir // --------------------------------------------------------------------------------
354*cdf0e10cSrcweir void SAL_CALL OConnection::rollback(  ) throw(SQLException, RuntimeException)
355*cdf0e10cSrcweir {
356*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
357*cdf0e10cSrcweir 	checkDisposed(OConnection_BASE::rBHelper.bDisposed);
358*cdf0e10cSrcweir 
359*cdf0e10cSrcweir 
360*cdf0e10cSrcweir 	OTools::ThrowException(this,N3SQLEndTran(SQL_HANDLE_DBC,m_aConnectionHandle,SQL_ROLLBACK),m_aConnectionHandle,SQL_HANDLE_DBC,*this);
361*cdf0e10cSrcweir }
362*cdf0e10cSrcweir // --------------------------------------------------------------------------------
363*cdf0e10cSrcweir sal_Bool SAL_CALL OConnection::isClosed(  ) throw(SQLException, RuntimeException)
364*cdf0e10cSrcweir {
365*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
366*cdf0e10cSrcweir 
367*cdf0e10cSrcweir 	return OConnection_BASE::rBHelper.bDisposed;
368*cdf0e10cSrcweir }
369*cdf0e10cSrcweir // --------------------------------------------------------------------------------
370*cdf0e10cSrcweir Reference< XDatabaseMetaData > SAL_CALL OConnection::getMetaData(  ) throw(SQLException, RuntimeException)
371*cdf0e10cSrcweir {
372*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
373*cdf0e10cSrcweir 	checkDisposed(OConnection_BASE::rBHelper.bDisposed);
374*cdf0e10cSrcweir 
375*cdf0e10cSrcweir 	Reference< XDatabaseMetaData > xMetaData = m_xMetaData;
376*cdf0e10cSrcweir 	if(!xMetaData.is())
377*cdf0e10cSrcweir 	{
378*cdf0e10cSrcweir 		xMetaData = new ODatabaseMetaData(m_aConnectionHandle,this);
379*cdf0e10cSrcweir 		m_xMetaData = xMetaData;
380*cdf0e10cSrcweir 	}
381*cdf0e10cSrcweir 
382*cdf0e10cSrcweir 	return xMetaData;
383*cdf0e10cSrcweir }
384*cdf0e10cSrcweir // --------------------------------------------------------------------------------
385*cdf0e10cSrcweir void SAL_CALL OConnection::setReadOnly( sal_Bool readOnly ) throw(SQLException, RuntimeException)
386*cdf0e10cSrcweir {
387*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
388*cdf0e10cSrcweir 	checkDisposed(OConnection_BASE::rBHelper.bDisposed);
389*cdf0e10cSrcweir 
390*cdf0e10cSrcweir 
391*cdf0e10cSrcweir 	OTools::ThrowException(this,
392*cdf0e10cSrcweir         N3SQLSetConnectAttr(m_aConnectionHandle,SQL_ATTR_ACCESS_MODE,reinterpret_cast< SQLPOINTER >( readOnly ),SQL_IS_INTEGER),
393*cdf0e10cSrcweir 		m_aConnectionHandle,SQL_HANDLE_DBC,*this);
394*cdf0e10cSrcweir }
395*cdf0e10cSrcweir // --------------------------------------------------------------------------------
396*cdf0e10cSrcweir sal_Bool SAL_CALL OConnection::isReadOnly() throw(SQLException, RuntimeException)
397*cdf0e10cSrcweir {
398*cdf0e10cSrcweir 	// const member which will initialized only once
399*cdf0e10cSrcweir 	return m_bReadOnly;
400*cdf0e10cSrcweir }
401*cdf0e10cSrcweir // --------------------------------------------------------------------------------
402*cdf0e10cSrcweir void SAL_CALL OConnection::setCatalog( const ::rtl::OUString& catalog ) throw(SQLException, RuntimeException)
403*cdf0e10cSrcweir {
404*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
405*cdf0e10cSrcweir 	checkDisposed(OConnection_BASE::rBHelper.bDisposed);
406*cdf0e10cSrcweir 
407*cdf0e10cSrcweir 
408*cdf0e10cSrcweir 	::rtl::OString aCat(::rtl::OUStringToOString(catalog.getStr(),getTextEncoding()));
409*cdf0e10cSrcweir 	OTools::ThrowException(this,
410*cdf0e10cSrcweir 		N3SQLSetConnectAttr(m_aConnectionHandle,SQL_ATTR_CURRENT_CATALOG,(SDB_ODBC_CHAR*)aCat.getStr(),SQL_NTS),
411*cdf0e10cSrcweir 		m_aConnectionHandle,SQL_HANDLE_DBC,*this);
412*cdf0e10cSrcweir }
413*cdf0e10cSrcweir // --------------------------------------------------------------------------------
414*cdf0e10cSrcweir ::rtl::OUString SAL_CALL OConnection::getCatalog(  ) throw(SQLException, RuntimeException)
415*cdf0e10cSrcweir {
416*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
417*cdf0e10cSrcweir 	checkDisposed(OConnection_BASE::rBHelper.bDisposed);
418*cdf0e10cSrcweir 
419*cdf0e10cSrcweir 
420*cdf0e10cSrcweir 	sal_Int32 nValueLen;
421*cdf0e10cSrcweir 	char pCat[1024];
422*cdf0e10cSrcweir 	OTools::ThrowException(this,
423*cdf0e10cSrcweir 		N3SQLGetConnectAttr(m_aConnectionHandle,SQL_ATTR_CURRENT_CATALOG,(SDB_ODBC_CHAR*)pCat,(sizeof pCat)-1,&nValueLen),
424*cdf0e10cSrcweir 		m_aConnectionHandle,SQL_HANDLE_DBC,*this);
425*cdf0e10cSrcweir 
426*cdf0e10cSrcweir 	return ::rtl::OUString(pCat,nValueLen,getTextEncoding());
427*cdf0e10cSrcweir }
428*cdf0e10cSrcweir // --------------------------------------------------------------------------------
429*cdf0e10cSrcweir void SAL_CALL OConnection::setTransactionIsolation( sal_Int32 level ) throw(SQLException, RuntimeException)
430*cdf0e10cSrcweir {
431*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
432*cdf0e10cSrcweir 	checkDisposed(OConnection_BASE::rBHelper.bDisposed);
433*cdf0e10cSrcweir 
434*cdf0e10cSrcweir 
435*cdf0e10cSrcweir 	OTools::ThrowException(this,N3SQLSetConnectAttr(m_aConnectionHandle,
436*cdf0e10cSrcweir 								   SQL_ATTR_TXN_ISOLATION,
437*cdf0e10cSrcweir 								   (SQLPOINTER)level,SQL_IS_INTEGER),
438*cdf0e10cSrcweir 								   m_aConnectionHandle,SQL_HANDLE_DBC,*this);
439*cdf0e10cSrcweir }
440*cdf0e10cSrcweir // --------------------------------------------------------------------------------
441*cdf0e10cSrcweir sal_Int32 SAL_CALL OConnection::getTransactionIsolation(  ) throw(SQLException, RuntimeException)
442*cdf0e10cSrcweir {
443*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
444*cdf0e10cSrcweir 	checkDisposed(OConnection_BASE::rBHelper.bDisposed);
445*cdf0e10cSrcweir 
446*cdf0e10cSrcweir 
447*cdf0e10cSrcweir 	sal_Int32 nTxn = 0;
448*cdf0e10cSrcweir 	SQLINTEGER nValueLen;
449*cdf0e10cSrcweir 	OTools::ThrowException(this,
450*cdf0e10cSrcweir 		N3SQLGetConnectAttr(m_aConnectionHandle,SQL_ATTR_TXN_ISOLATION,&nTxn,sizeof nTxn,&nValueLen),
451*cdf0e10cSrcweir 		m_aConnectionHandle,SQL_HANDLE_DBC,*this);
452*cdf0e10cSrcweir 	return nTxn;
453*cdf0e10cSrcweir }
454*cdf0e10cSrcweir // --------------------------------------------------------------------------------
455*cdf0e10cSrcweir Reference< ::com::sun::star::container::XNameAccess > SAL_CALL OConnection::getTypeMap(  ) throw(SQLException, RuntimeException)
456*cdf0e10cSrcweir {
457*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
458*cdf0e10cSrcweir 	checkDisposed(OConnection_BASE::rBHelper.bDisposed);
459*cdf0e10cSrcweir 
460*cdf0e10cSrcweir 
461*cdf0e10cSrcweir 	return NULL;
462*cdf0e10cSrcweir }
463*cdf0e10cSrcweir // --------------------------------------------------------------------------------
464*cdf0e10cSrcweir void SAL_CALL OConnection::setTypeMap( const Reference< ::com::sun::star::container::XNameAccess >& /*typeMap*/ ) throw(SQLException, RuntimeException)
465*cdf0e10cSrcweir {
466*cdf0e10cSrcweir     ::dbtools::throwFeatureNotImplementedException( "XConnection::setTypeMap", *this );
467*cdf0e10cSrcweir }
468*cdf0e10cSrcweir // --------------------------------------------------------------------------------
469*cdf0e10cSrcweir // XCloseable
470*cdf0e10cSrcweir void SAL_CALL OConnection::close(  ) throw(SQLException, RuntimeException)
471*cdf0e10cSrcweir {
472*cdf0e10cSrcweir 	{
473*cdf0e10cSrcweir 		::osl::MutexGuard aGuard( m_aMutex );
474*cdf0e10cSrcweir 		checkDisposed(OConnection_BASE::rBHelper.bDisposed);
475*cdf0e10cSrcweir 
476*cdf0e10cSrcweir 	}
477*cdf0e10cSrcweir 	dispose();
478*cdf0e10cSrcweir }
479*cdf0e10cSrcweir // --------------------------------------------------------------------------------
480*cdf0e10cSrcweir // XWarningsSupplier
481*cdf0e10cSrcweir Any SAL_CALL OConnection::getWarnings(  ) throw(SQLException, RuntimeException)
482*cdf0e10cSrcweir {
483*cdf0e10cSrcweir 	return Any();
484*cdf0e10cSrcweir }
485*cdf0e10cSrcweir // --------------------------------------------------------------------------------
486*cdf0e10cSrcweir void SAL_CALL OConnection::clearWarnings(  ) throw(SQLException, RuntimeException)
487*cdf0e10cSrcweir {
488*cdf0e10cSrcweir }
489*cdf0e10cSrcweir //--------------------------------------------------------------------
490*cdf0e10cSrcweir void OConnection::buildTypeInfo() throw( SQLException)
491*cdf0e10cSrcweir {
492*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
493*cdf0e10cSrcweir 
494*cdf0e10cSrcweir 	Reference< XResultSet> xRs = getMetaData ()->getTypeInfo ();
495*cdf0e10cSrcweir 	if(xRs.is())
496*cdf0e10cSrcweir 	{
497*cdf0e10cSrcweir 		Reference< XRow> xRow(xRs,UNO_QUERY);
498*cdf0e10cSrcweir 		// Information for a single SQL type
499*cdf0e10cSrcweir 
500*cdf0e10cSrcweir 		::connectivity::ORowSetValue aValue;
501*cdf0e10cSrcweir 		::std::vector<sal_Int32> aTypes;
502*cdf0e10cSrcweir 		Reference<XResultSetMetaData> xResultSetMetaData = Reference<XResultSetMetaDataSupplier>(xRs,UNO_QUERY)->getMetaData();
503*cdf0e10cSrcweir         sal_Int32 nCount = xResultSetMetaData->getColumnCount();
504*cdf0e10cSrcweir 		// Loop on the result set until we reach end of file
505*cdf0e10cSrcweir 		while (xRs->next ())
506*cdf0e10cSrcweir 		{
507*cdf0e10cSrcweir 			OTypeInfo aInfo;
508*cdf0e10cSrcweir 			sal_Int32 nPos = 1;
509*cdf0e10cSrcweir             if ( aTypes.empty() )
510*cdf0e10cSrcweir             {
511*cdf0e10cSrcweir                 if ( nCount < 1 )
512*cdf0e10cSrcweir                     nCount = 18;
513*cdf0e10cSrcweir                 aTypes.reserve(nCount+1);
514*cdf0e10cSrcweir                 aTypes.push_back(-1);
515*cdf0e10cSrcweir                 for (sal_Int32 j = 1; j <= nCount ; ++j)
516*cdf0e10cSrcweir                     aTypes.push_back(xResultSetMetaData->getColumnType(j));
517*cdf0e10cSrcweir             }
518*cdf0e10cSrcweir 
519*cdf0e10cSrcweir             aValue.fill(nPos,aTypes[nPos],xRow);
520*cdf0e10cSrcweir 			aInfo.aTypeName		= aValue;
521*cdf0e10cSrcweir 			++nPos;
522*cdf0e10cSrcweir             aValue.fill(nPos,aTypes[nPos],xRow);
523*cdf0e10cSrcweir 			aInfo.nType			= aValue;
524*cdf0e10cSrcweir 			++nPos;
525*cdf0e10cSrcweir             aValue.fill(nPos,aTypes[nPos],xRow);
526*cdf0e10cSrcweir 			aInfo.nPrecision		= aValue;
527*cdf0e10cSrcweir 			++nPos;
528*cdf0e10cSrcweir             aValue.fill(nPos,aTypes[nPos],xRow);
529*cdf0e10cSrcweir 			aInfo.aLiteralPrefix	= aValue;
530*cdf0e10cSrcweir 			++nPos;
531*cdf0e10cSrcweir             aValue.fill(nPos,aTypes[nPos],xRow);
532*cdf0e10cSrcweir 			aInfo.aLiteralSuffix	= aValue;
533*cdf0e10cSrcweir 			++nPos;
534*cdf0e10cSrcweir             aValue.fill(nPos,aTypes[nPos],xRow);
535*cdf0e10cSrcweir 			aInfo.aCreateParams	= aValue;
536*cdf0e10cSrcweir 			++nPos;
537*cdf0e10cSrcweir             aValue.fill(nPos,aTypes[nPos],xRow);
538*cdf0e10cSrcweir 			aInfo.bNullable		= (sal_Int32)aValue == ColumnValue::NULLABLE;
539*cdf0e10cSrcweir 			++nPos;
540*cdf0e10cSrcweir             aValue.fill(nPos,aTypes[nPos],xRow);
541*cdf0e10cSrcweir 			aInfo.bCaseSensitive	= (sal_Bool)aValue;
542*cdf0e10cSrcweir 			++nPos;
543*cdf0e10cSrcweir             aValue.fill(nPos,aTypes[nPos],xRow);
544*cdf0e10cSrcweir 			aInfo.nSearchType		= aValue;
545*cdf0e10cSrcweir 			++nPos;
546*cdf0e10cSrcweir             aValue.fill(nPos,aTypes[nPos],xRow);
547*cdf0e10cSrcweir 			aInfo.bUnsigned		= (sal_Bool)aValue;
548*cdf0e10cSrcweir 			++nPos;
549*cdf0e10cSrcweir             aValue.fill(nPos,aTypes[nPos],xRow);
550*cdf0e10cSrcweir 			aInfo.bCurrency		= (sal_Bool)aValue;
551*cdf0e10cSrcweir 			++nPos;
552*cdf0e10cSrcweir             aValue.fill(nPos,aTypes[nPos],xRow);
553*cdf0e10cSrcweir 			aInfo.bAutoIncrement	= (sal_Bool)aValue;
554*cdf0e10cSrcweir 			++nPos;
555*cdf0e10cSrcweir             aValue.fill(nPos,aTypes[nPos],xRow);
556*cdf0e10cSrcweir 			aInfo.aLocalTypeName	= aValue;
557*cdf0e10cSrcweir 			++nPos;
558*cdf0e10cSrcweir             aValue.fill(nPos,aTypes[nPos],xRow);
559*cdf0e10cSrcweir 			aInfo.nMinimumScale	= aValue;
560*cdf0e10cSrcweir 			++nPos;
561*cdf0e10cSrcweir             aValue.fill(nPos,aTypes[nPos],xRow);
562*cdf0e10cSrcweir 			aInfo.nMaximumScale	= aValue;
563*cdf0e10cSrcweir             if ( nCount >= 18 )
564*cdf0e10cSrcweir             {
565*cdf0e10cSrcweir                 nPos = 18;
566*cdf0e10cSrcweir                 aValue.fill(nPos,aTypes[nPos],xRow);
567*cdf0e10cSrcweir 			    aInfo.nNumPrecRadix	= aValue;
568*cdf0e10cSrcweir             }
569*cdf0e10cSrcweir 
570*cdf0e10cSrcweir 			// check if values are less than zero like it happens in a oracle jdbc driver
571*cdf0e10cSrcweir 			if( aInfo.nPrecision < 0)
572*cdf0e10cSrcweir 				aInfo.nPrecision = 0;
573*cdf0e10cSrcweir 			if( aInfo.nMinimumScale < 0)
574*cdf0e10cSrcweir 				aInfo.nMinimumScale = 0;
575*cdf0e10cSrcweir 			if( aInfo.nMaximumScale < 0)
576*cdf0e10cSrcweir 				aInfo.nMaximumScale = 0;
577*cdf0e10cSrcweir 			if( aInfo.nNumPrecRadix < 0)
578*cdf0e10cSrcweir 				aInfo.nNumPrecRadix = 10;
579*cdf0e10cSrcweir 
580*cdf0e10cSrcweir 			// Now that we have the type info, save it
581*cdf0e10cSrcweir 			// in the Hashtable if we don't already have an
582*cdf0e10cSrcweir 			// entry for this SQL type.
583*cdf0e10cSrcweir 
584*cdf0e10cSrcweir 			m_aTypeInfo.push_back(aInfo);
585*cdf0e10cSrcweir 		}
586*cdf0e10cSrcweir 
587*cdf0e10cSrcweir 		// Close the result set/statement.
588*cdf0e10cSrcweir 
589*cdf0e10cSrcweir 		Reference< XCloseable> xClose(xRs,UNO_QUERY);
590*cdf0e10cSrcweir 		if(xClose.is())
591*cdf0e10cSrcweir 			xClose->close();
592*cdf0e10cSrcweir 	}
593*cdf0e10cSrcweir }
594*cdf0e10cSrcweir //------------------------------------------------------------------------------
595*cdf0e10cSrcweir void OConnection::disposing()
596*cdf0e10cSrcweir {
597*cdf0e10cSrcweir 	::osl::MutexGuard aGuard(m_aMutex);
598*cdf0e10cSrcweir 
599*cdf0e10cSrcweir     OConnection_BASE::disposing();
600*cdf0e10cSrcweir 
601*cdf0e10cSrcweir 	for (::std::map< SQLHANDLE,OConnection*>::iterator aConIter = m_aConnections.begin();aConIter != m_aConnections.end();++aConIter )
602*cdf0e10cSrcweir 		aConIter->second->dispose();
603*cdf0e10cSrcweir 
604*cdf0e10cSrcweir 	::std::map< SQLHANDLE,OConnection*>().swap(m_aConnections);
605*cdf0e10cSrcweir 
606*cdf0e10cSrcweir 	if(!m_bClosed)
607*cdf0e10cSrcweir 		N3SQLDisconnect(m_aConnectionHandle);
608*cdf0e10cSrcweir 	m_bClosed	= sal_True;
609*cdf0e10cSrcweir 
610*cdf0e10cSrcweir 	dispose_ChildImpl();
611*cdf0e10cSrcweir }
612*cdf0e10cSrcweir // -----------------------------------------------------------------------------
613*cdf0e10cSrcweir OConnection* OConnection::cloneConnection()
614*cdf0e10cSrcweir {
615*cdf0e10cSrcweir 	return new OConnection(m_pDriverHandleCopy,m_pDriver);
616*cdf0e10cSrcweir }
617*cdf0e10cSrcweir // -----------------------------------------------------------------------------
618*cdf0e10cSrcweir SQLHANDLE OConnection::createStatementHandle()
619*cdf0e10cSrcweir {
620*cdf0e10cSrcweir 	OConnection* pConnectionTemp = this;
621*cdf0e10cSrcweir 	sal_Bool bNew = sal_False;
622*cdf0e10cSrcweir 	try
623*cdf0e10cSrcweir 	{
624*cdf0e10cSrcweir 		sal_Int32 nMaxStatements = getMetaData()->getMaxStatements();
625*cdf0e10cSrcweir 		if(nMaxStatements && nMaxStatements <= m_nStatementCount)
626*cdf0e10cSrcweir 		{
627*cdf0e10cSrcweir 			OConnection* pConnection = cloneConnection();
628*cdf0e10cSrcweir 			pConnection->acquire();
629*cdf0e10cSrcweir 			pConnection->Construct(m_sURL,getConnectionInfo());
630*cdf0e10cSrcweir 			pConnectionTemp = pConnection;
631*cdf0e10cSrcweir 			bNew = sal_True;
632*cdf0e10cSrcweir 		}
633*cdf0e10cSrcweir 	}
634*cdf0e10cSrcweir 	catch(SQLException&)
635*cdf0e10cSrcweir 	{
636*cdf0e10cSrcweir 	}
637*cdf0e10cSrcweir 
638*cdf0e10cSrcweir 	SQLHANDLE aStatementHandle = SQL_NULL_HANDLE;
639*cdf0e10cSrcweir 	SQLRETURN nRetcode = N3SQLAllocHandle(SQL_HANDLE_STMT,pConnectionTemp->getConnection(),&aStatementHandle);
640*cdf0e10cSrcweir     OSL_UNUSED( nRetcode );
641*cdf0e10cSrcweir 	++m_nStatementCount;
642*cdf0e10cSrcweir 	if(bNew)
643*cdf0e10cSrcweir 		m_aConnections.insert(::std::map< SQLHANDLE,OConnection*>::value_type(aStatementHandle,pConnectionTemp));
644*cdf0e10cSrcweir 
645*cdf0e10cSrcweir 	return aStatementHandle;
646*cdf0e10cSrcweir 
647*cdf0e10cSrcweir }
648*cdf0e10cSrcweir // -----------------------------------------------------------------------------
649*cdf0e10cSrcweir void OConnection::freeStatementHandle(SQLHANDLE& _pHandle)
650*cdf0e10cSrcweir {
651*cdf0e10cSrcweir 	::std::map< SQLHANDLE,OConnection*>::iterator aFind = m_aConnections.find(_pHandle);
652*cdf0e10cSrcweir 
653*cdf0e10cSrcweir 	N3SQLFreeStmt(_pHandle,SQL_RESET_PARAMS);
654*cdf0e10cSrcweir 	N3SQLFreeStmt(_pHandle,SQL_UNBIND);
655*cdf0e10cSrcweir 	N3SQLFreeStmt(_pHandle,SQL_CLOSE);
656*cdf0e10cSrcweir 	N3SQLFreeHandle(SQL_HANDLE_STMT,_pHandle);
657*cdf0e10cSrcweir 
658*cdf0e10cSrcweir 	_pHandle = SQL_NULL_HANDLE;
659*cdf0e10cSrcweir 
660*cdf0e10cSrcweir 	if(aFind != m_aConnections.end())
661*cdf0e10cSrcweir 	{
662*cdf0e10cSrcweir 		aFind->second->dispose();
663*cdf0e10cSrcweir 		m_aConnections.erase(aFind);
664*cdf0e10cSrcweir 	}
665*cdf0e10cSrcweir 	--m_nStatementCount;
666*cdf0e10cSrcweir }
667*cdf0e10cSrcweir // -----------------------------------------------------------------------------
668*cdf0e10cSrcweir 
669*cdf0e10cSrcweir 
670*cdf0e10cSrcweir 
671