1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3*cdf0e10cSrcweir *
4*cdf0e10cSrcweir * Copyright 2008 by Sun Microsystems, Inc.
5*cdf0e10cSrcweir *
6*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite
7*cdf0e10cSrcweir *
8*cdf0e10cSrcweir * $RCSfile: mysqlc_connection.cxx,v $
9*cdf0e10cSrcweir *
10*cdf0e10cSrcweir * $Revision: 1.1.2.6 $*
11*cdf0e10cSrcweir * This file is part of OpenOffice.org.
12*cdf0e10cSrcweir *
13*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify
14*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3
15*cdf0e10cSrcweir * only, as published by the Free Software Foundation.
16*cdf0e10cSrcweir *
17*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful,
18*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of
19*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details
21*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code).
22*cdf0e10cSrcweir *
23*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License
24*cdf0e10cSrcweir * version 3 along with OpenOffice.org.  If not, see
25*cdf0e10cSrcweir * <http://www.openoffice.org/license.html>
26*cdf0e10cSrcweir * for a copy of the LGPLv3 License.
27*cdf0e10cSrcweir ************************************************************************/
28*cdf0e10cSrcweir 
29*cdf0e10cSrcweir #include "mysqlc_connection.hxx"
30*cdf0e10cSrcweir #include "mysqlc_databasemetadata.hxx"
31*cdf0e10cSrcweir 
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir #include "mysqlc_driver.hxx"
34*cdf0e10cSrcweir #include "mysqlc_statement.hxx"
35*cdf0e10cSrcweir #include "mysqlc_preparedstatement.hxx"
36*cdf0e10cSrcweir #include "mysqlc_general.hxx"
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir #include <preextstl.h>
39*cdf0e10cSrcweir #include <cppconn/driver.h>
40*cdf0e10cSrcweir #include <cppconn/connection.h>
41*cdf0e10cSrcweir #include <cppconn/statement.h>
42*cdf0e10cSrcweir #include <cppconn/metadata.h>
43*cdf0e10cSrcweir #include <cppconn/exception.h>
44*cdf0e10cSrcweir #include <postextstl.h>
45*cdf0e10cSrcweir 
46*cdf0e10cSrcweir #include <com/sun/star/sdbc/ColumnValue.hpp>
47*cdf0e10cSrcweir #include <com/sun/star/sdbc/XRow.hpp>
48*cdf0e10cSrcweir #include <com/sun/star/sdbc/TransactionIsolation.hpp>
49*cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp>
50*cdf0e10cSrcweir #include <com/sun/star/beans/NamedValue.hpp>
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir #include <osl/module.hxx>
53*cdf0e10cSrcweir #include <osl/thread.h>
54*cdf0e10cSrcweir #include <osl/file.h>
55*cdf0e10cSrcweir #include <rtl/uri.hxx>
56*cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
57*cdf0e10cSrcweir 
58*cdf0e10cSrcweir using namespace connectivity::mysqlc;
59*cdf0e10cSrcweir 
60*cdf0e10cSrcweir #include <stdio.h>
61*cdf0e10cSrcweir 
62*cdf0e10cSrcweir //------------------------------------------------------------------------------
63*cdf0e10cSrcweir using namespace com::sun::star::uno;
64*cdf0e10cSrcweir using namespace com::sun::star::container;
65*cdf0e10cSrcweir using namespace com::sun::star::lang;
66*cdf0e10cSrcweir using namespace com::sun::star::beans;
67*cdf0e10cSrcweir using namespace com::sun::star::sdbc;
68*cdf0e10cSrcweir using ::osl::MutexGuard;
69*cdf0e10cSrcweir using ::rtl::OUString;
70*cdf0e10cSrcweir 
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir #define MYSQLC_URI_PREFIX "sdbc:mysqlc:"
73*cdf0e10cSrcweir 
74*cdf0e10cSrcweir 
75*cdf0e10cSrcweir /* {{{ OConnection::OConnection() -I- */
76*cdf0e10cSrcweir OConnection::OConnection(MysqlCDriver& _rDriver, sql::Driver * _cppDriver)
77*cdf0e10cSrcweir 	:OMetaConnection_BASE(m_aMutex)
78*cdf0e10cSrcweir 	,OSubComponent<OConnection, OConnection_BASE>((::cppu::OWeakObject*)&_rDriver, this)
79*cdf0e10cSrcweir 	,m_xMetaData(NULL)
80*cdf0e10cSrcweir 	,m_rDriver(_rDriver)
81*cdf0e10cSrcweir 	,cppDriver(_cppDriver)
82*cdf0e10cSrcweir 	,m_bClosed(sal_False)
83*cdf0e10cSrcweir 	,m_bUseCatalog(sal_False)
84*cdf0e10cSrcweir 	,m_bUseOldDateFormat(sal_False)
85*cdf0e10cSrcweir {
86*cdf0e10cSrcweir 	OSL_TRACE("OConnection::OConnection");
87*cdf0e10cSrcweir 	m_rDriver.acquire();
88*cdf0e10cSrcweir }
89*cdf0e10cSrcweir /* }}} */
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir 
92*cdf0e10cSrcweir /* {{{ OConnection::OConnection() -I- */
93*cdf0e10cSrcweir OConnection::~OConnection()
94*cdf0e10cSrcweir {
95*cdf0e10cSrcweir 	OSL_TRACE("OConnection::~OConnection");
96*cdf0e10cSrcweir 	if (!isClosed()) {
97*cdf0e10cSrcweir 		close();
98*cdf0e10cSrcweir 	}
99*cdf0e10cSrcweir 	m_rDriver.release();
100*cdf0e10cSrcweir }
101*cdf0e10cSrcweir /* }}} */
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir 
104*cdf0e10cSrcweir /* {{{ OConnection::release() -I- */
105*cdf0e10cSrcweir void SAL_CALL OConnection::release()
106*cdf0e10cSrcweir 	throw()
107*cdf0e10cSrcweir {
108*cdf0e10cSrcweir 	OSL_TRACE("OConnection::release");
109*cdf0e10cSrcweir 	relase_ChildImpl();
110*cdf0e10cSrcweir }
111*cdf0e10cSrcweir /* }}} */
112*cdf0e10cSrcweir 
113*cdf0e10cSrcweir #ifndef SYSTEM_MYSQL
114*cdf0e10cSrcweir     extern "C" { void SAL_CALL thisModule() {} }
115*cdf0e10cSrcweir #endif
116*cdf0e10cSrcweir 
117*cdf0e10cSrcweir /* {{{ OConnection::construct() -I- */
118*cdf0e10cSrcweir void OConnection::construct(const OUString& url, const Sequence< PropertyValue >& info)
119*cdf0e10cSrcweir 	throw(SQLException)
120*cdf0e10cSrcweir {
121*cdf0e10cSrcweir 	OSL_TRACE("OConnection::construct");
122*cdf0e10cSrcweir 	MutexGuard aGuard(m_aMutex);
123*cdf0e10cSrcweir 
124*cdf0e10cSrcweir 	sal_Int32 nIndex;
125*cdf0e10cSrcweir 	sal_Bool  bEmbedded = sal_False;
126*cdf0e10cSrcweir 	OUString token;
127*cdf0e10cSrcweir 	OUString aHostName(RTL_CONSTASCII_USTRINGPARAM("localhost"));
128*cdf0e10cSrcweir     sal_Int32 nPort = 3306;
129*cdf0e10cSrcweir 	OUString aDbName;
130*cdf0e10cSrcweir 
131*cdf0e10cSrcweir 	m_settings.encoding = m_rDriver.getDefaultEncoding();
132*cdf0e10cSrcweir 	m_settings.quoteIdentifier = OUString();
133*cdf0e10cSrcweir 
134*cdf0e10cSrcweir 	// parse url. Url has the following format:
135*cdf0e10cSrcweir 	// external server: sdbc:mysqlc:[hostname]:[port]/[dbname]
136*cdf0e10cSrcweir 
137*cdf0e10cSrcweir 	if (!url.compareTo(OUString::createFromAscii(MYSQLC_URI_PREFIX), sizeof(MYSQLC_URI_PREFIX)-1)) {
138*cdf0e10cSrcweir 		nIndex = 12;
139*cdf0e10cSrcweir 	} else {
140*cdf0e10cSrcweir 		bEmbedded = sal_True;
141*cdf0e10cSrcweir 		nIndex = 20;
142*cdf0e10cSrcweir 		mysqlc_sdbc_driver::throwFeatureNotImplementedException("OConnection::construct (embedded MySQL)", *this);
143*cdf0e10cSrcweir 	}
144*cdf0e10cSrcweir 
145*cdf0e10cSrcweir 	token = url.getToken(0, '/', nIndex);
146*cdf0e10cSrcweir 	if (token.getLength()) {
147*cdf0e10cSrcweir 		sal_Int32 nIndex1 = 0;
148*cdf0e10cSrcweir 		OUString hostandport = token.getToken(0,':', nIndex1);
149*cdf0e10cSrcweir 		if (hostandport.getLength()) {
150*cdf0e10cSrcweir 			aHostName = hostandport;
151*cdf0e10cSrcweir 			hostandport = token.getToken(0, ':', nIndex1);
152*cdf0e10cSrcweir 			if (hostandport.getLength() && nIndex1) {
153*cdf0e10cSrcweir                 nPort = hostandport.toInt32();
154*cdf0e10cSrcweir 			}
155*cdf0e10cSrcweir 			token = url.getToken(0, '/', nIndex);
156*cdf0e10cSrcweir 			if (token.getLength() && nIndex) {
157*cdf0e10cSrcweir 				aDbName = token;
158*cdf0e10cSrcweir 			}
159*cdf0e10cSrcweir 		}
160*cdf0e10cSrcweir 	}
161*cdf0e10cSrcweir 
162*cdf0e10cSrcweir 	// get user and password for mysql connection
163*cdf0e10cSrcweir 	const PropertyValue *pIter	= info.getConstArray();
164*cdf0e10cSrcweir 	const PropertyValue *pEnd	= pIter + info.getLength();
165*cdf0e10cSrcweir 	OUString aUser, aPass, sUnixSocket, sNamedPipe;
166*cdf0e10cSrcweir 	bool unixSocketPassed = false;
167*cdf0e10cSrcweir 	bool namedPipePassed = false;
168*cdf0e10cSrcweir 
169*cdf0e10cSrcweir 	m_settings.connectionURL = url;
170*cdf0e10cSrcweir 	for (;pIter != pEnd;++pIter) {
171*cdf0e10cSrcweir 		if (!pIter->Name.compareToAscii("user")) {
172*cdf0e10cSrcweir 			OSL_VERIFY( pIter->Value >>= aUser );
173*cdf0e10cSrcweir 		} else if (!pIter->Name.compareToAscii("password")) {
174*cdf0e10cSrcweir 			OSL_VERIFY( pIter->Value >>= aPass );
175*cdf0e10cSrcweir 		} else if (!pIter->Name.compareToAscii("LocalSocket")) {
176*cdf0e10cSrcweir 			OSL_VERIFY( pIter->Value >>= sUnixSocket );
177*cdf0e10cSrcweir 			unixSocketPassed = true;
178*cdf0e10cSrcweir 		} else if (!pIter->Name.compareToAscii("NamedPipe")) {
179*cdf0e10cSrcweir 			OSL_VERIFY( pIter->Value >>= sNamedPipe );
180*cdf0e10cSrcweir 			namedPipePassed = true;
181*cdf0e10cSrcweir 		} else if ( !pIter->Name.compareToAscii("PublicConnectionURL")) {
182*cdf0e10cSrcweir 			OSL_VERIFY( pIter->Value >>= m_settings.connectionURL );
183*cdf0e10cSrcweir 		} else if ( !pIter->Name.compareToAscii("NewURL")) {    // legacy name for "PublicConnectionURL"
184*cdf0e10cSrcweir 			OSL_VERIFY( pIter->Value >>= m_settings.connectionURL );
185*cdf0e10cSrcweir         }
186*cdf0e10cSrcweir 	}
187*cdf0e10cSrcweir 
188*cdf0e10cSrcweir 	if (bEmbedded == sal_False) {
189*cdf0e10cSrcweir 		try {
190*cdf0e10cSrcweir             sql::ConnectOptionsMap connProps;
191*cdf0e10cSrcweir 			ext_std::string host_str = OUStringToOString(aHostName, m_settings.encoding).getStr();
192*cdf0e10cSrcweir 			ext_std::string user_str = OUStringToOString(aUser, m_settings.encoding).getStr();
193*cdf0e10cSrcweir 			ext_std::string pass_str = OUStringToOString(aPass, m_settings.encoding).getStr();
194*cdf0e10cSrcweir 			ext_std::string schema_str = OUStringToOString(aDbName, m_settings.encoding).getStr();
195*cdf0e10cSrcweir 			connProps["hostName"] = sql::ConnectPropertyVal(host_str);
196*cdf0e10cSrcweir 			connProps["userName"] = sql::ConnectPropertyVal(user_str);
197*cdf0e10cSrcweir 			connProps["password"] = sql::ConnectPropertyVal(pass_str);
198*cdf0e10cSrcweir 			connProps["schema"] = sql::ConnectPropertyVal(schema_str);
199*cdf0e10cSrcweir 			connProps["port"] = sql::ConnectPropertyVal((int)(nPort));
200*cdf0e10cSrcweir 			if (unixSocketPassed) {
201*cdf0e10cSrcweir 				sql::SQLString socket_str = OUStringToOString(sUnixSocket, m_settings.encoding).getStr();
202*cdf0e10cSrcweir 				connProps["socket"] = socket_str;
203*cdf0e10cSrcweir 			} else if (namedPipePassed) {
204*cdf0e10cSrcweir 				sql::SQLString pipe_str = OUStringToOString(sNamedPipe, m_settings.encoding).getStr();
205*cdf0e10cSrcweir 				connProps["socket"] = pipe_str;
206*cdf0e10cSrcweir 			}
207*cdf0e10cSrcweir 
208*cdf0e10cSrcweir #ifndef SYSTEM_MYSQL
209*cdf0e10cSrcweir             ::rtl::OUString sMySQLClientLib( RTL_CONSTASCII_USTRINGPARAM( MYSQL_LIB ) );
210*cdf0e10cSrcweir 
211*cdf0e10cSrcweir             ::rtl::OUString moduleBase;
212*cdf0e10cSrcweir             OSL_VERIFY( ::osl::Module::getUrlFromAddress( &thisModule, moduleBase ) );
213*cdf0e10cSrcweir             ::rtl::OUString sMySQLClientLibURL;
214*cdf0e10cSrcweir             try
215*cdf0e10cSrcweir             {
216*cdf0e10cSrcweir                 sMySQLClientLibURL = ::rtl::Uri::convertRelToAbs( moduleBase, sMySQLClientLib.pData );
217*cdf0e10cSrcweir             }
218*cdf0e10cSrcweir             catch ( const ::rtl::MalformedUriException& e )
219*cdf0e10cSrcweir             {
220*cdf0e10cSrcweir                 (void)e; // silence compiler
221*cdf0e10cSrcweir             #if OSL_DEBUG_LEVEL > 0
222*cdf0e10cSrcweir                 ::rtl::OString sMessage( "OConnection::construct: malformed URI: " );
223*cdf0e10cSrcweir                 sMessage += ::rtl::OUStringToOString( e.getMessage(), osl_getThreadTextEncoding() );
224*cdf0e10cSrcweir                 OSL_ENSURE( false, sMessage.getStr() );
225*cdf0e10cSrcweir             #endif
226*cdf0e10cSrcweir             }
227*cdf0e10cSrcweir 
228*cdf0e10cSrcweir             ::rtl::OUString sMySQLClientLibPath;
229*cdf0e10cSrcweir             osl_getSystemPathFromFileURL( sMySQLClientLibURL.pData, &sMySQLClientLibPath.pData );
230*cdf0e10cSrcweir 
231*cdf0e10cSrcweir             sql::SQLString mysqlLib = ::rtl::OUStringToOString( sMySQLClientLibPath, osl_getThreadTextEncoding() ).getStr();
232*cdf0e10cSrcweir             connProps["clientlib"] = mysqlLib;
233*cdf0e10cSrcweir 
234*cdf0e10cSrcweir             OSL_TRACE("clientlib=%s", mysqlLib.c_str());
235*cdf0e10cSrcweir #endif
236*cdf0e10cSrcweir 
237*cdf0e10cSrcweir 			OSL_TRACE("hostName=%s", host_str.c_str());
238*cdf0e10cSrcweir             OSL_TRACE("port=%i", int(nPort));
239*cdf0e10cSrcweir 			OSL_TRACE("userName=%s", user_str.c_str());
240*cdf0e10cSrcweir 			OSL_TRACE("password=%s", pass_str.c_str());
241*cdf0e10cSrcweir             OSL_TRACE("schema=%s", schema_str.c_str());
242*cdf0e10cSrcweir 
243*cdf0e10cSrcweir 			m_settings.cppConnection.reset(cppDriver->connect(connProps));
244*cdf0e10cSrcweir 		} catch (sql::SQLException &e) {
245*cdf0e10cSrcweir 			mysqlc_sdbc_driver::translateAndThrow(e, *this, getConnectionEncoding());
246*cdf0e10cSrcweir 		}
247*cdf0e10cSrcweir 	} else {
248*cdf0e10cSrcweir 		// TODO: support for embedded server
249*cdf0e10cSrcweir 	}
250*cdf0e10cSrcweir 
251*cdf0e10cSrcweir 	m_settings.schema = aDbName;
252*cdf0e10cSrcweir 	OSL_TRACE(OUStringToOString(m_settings.schema, getConnectionEncoding()).getStr());
253*cdf0e10cSrcweir 
254*cdf0e10cSrcweir 	// Check if the server is 4.1 or above
255*cdf0e10cSrcweir 	if (this->getMysqlVersion() < 40100) {
256*cdf0e10cSrcweir 		throw SQLException(
257*cdf0e10cSrcweir 			::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MySQL Connector/OO.org requires MySQL Server 4.1 or above" ) ),
258*cdf0e10cSrcweir 			*this,
259*cdf0e10cSrcweir 			::rtl::OUString(),
260*cdf0e10cSrcweir 			0,
261*cdf0e10cSrcweir 			Any());
262*cdf0e10cSrcweir 	}
263*cdf0e10cSrcweir 	std::auto_ptr<sql::Statement> stmt(m_settings.cppConnection->createStatement());
264*cdf0e10cSrcweir 	stmt->executeUpdate("SET session sql_mode='ANSI_QUOTES'");
265*cdf0e10cSrcweir 	stmt->executeUpdate("SET NAMES utf8");
266*cdf0e10cSrcweir }
267*cdf0e10cSrcweir /* }}} */
268*cdf0e10cSrcweir 
269*cdf0e10cSrcweir 
270*cdf0e10cSrcweir // XServiceInfo
271*cdf0e10cSrcweir IMPLEMENT_SERVICE_INFO(OConnection, "com.sun.star.sdbc.drivers.mysqlc.OConnection", "com.sun.star.sdbc.Connection")
272*cdf0e10cSrcweir 
273*cdf0e10cSrcweir 
274*cdf0e10cSrcweir /* {{{ OConnection::createStatement() -I- */
275*cdf0e10cSrcweir Reference< XStatement > SAL_CALL OConnection::createStatement()
276*cdf0e10cSrcweir 	throw(SQLException, RuntimeException)
277*cdf0e10cSrcweir {
278*cdf0e10cSrcweir 	OSL_TRACE("OConnection::createStatement");
279*cdf0e10cSrcweir 	MutexGuard aGuard(m_aMutex);
280*cdf0e10cSrcweir 	checkDisposed(OConnection_BASE::rBHelper.bDisposed);
281*cdf0e10cSrcweir 
282*cdf0e10cSrcweir 	// create a statement
283*cdf0e10cSrcweir 	Reference< XStatement > xReturn;
284*cdf0e10cSrcweir 	// the statement can only be executed once
285*cdf0e10cSrcweir 	try {
286*cdf0e10cSrcweir 		xReturn = new OStatement(this, m_settings.cppConnection->createStatement());
287*cdf0e10cSrcweir 		m_aStatements.push_back(WeakReferenceHelper(xReturn));
288*cdf0e10cSrcweir 		return xReturn;
289*cdf0e10cSrcweir 	} catch (sql::SQLException & e) {
290*cdf0e10cSrcweir 		mysqlc_sdbc_driver::translateAndThrow(e, *this, getConnectionEncoding());
291*cdf0e10cSrcweir 	}
292*cdf0e10cSrcweir 	return xReturn;
293*cdf0e10cSrcweir }
294*cdf0e10cSrcweir /* }}} */
295*cdf0e10cSrcweir 
296*cdf0e10cSrcweir 
297*cdf0e10cSrcweir /* {{{ OConnection::createStatement() -I- */
298*cdf0e10cSrcweir Reference< XPreparedStatement > SAL_CALL OConnection::prepareStatement(const OUString& _sSql)
299*cdf0e10cSrcweir 	throw(SQLException, RuntimeException)
300*cdf0e10cSrcweir {
301*cdf0e10cSrcweir 	OSL_TRACE("OConnection::prepareStatement");
302*cdf0e10cSrcweir 	MutexGuard aGuard(m_aMutex);
303*cdf0e10cSrcweir 	checkDisposed(OConnection_BASE::rBHelper.bDisposed);
304*cdf0e10cSrcweir 	const ::rtl::OUString sSqlStatement = transFormPreparedStatement( _sSql );
305*cdf0e10cSrcweir 
306*cdf0e10cSrcweir 	Reference< XPreparedStatement > xStatement;
307*cdf0e10cSrcweir 	try {
308*cdf0e10cSrcweir 		// create a statement
309*cdf0e10cSrcweir 		// the statement can only be executed more than once
310*cdf0e10cSrcweir 		xStatement = new OPreparedStatement(this,
311*cdf0e10cSrcweir 					m_settings.cppConnection->prepareStatement(OUStringToOString(sSqlStatement, getConnectionEncoding()).getStr()));
312*cdf0e10cSrcweir 		m_aStatements.push_back( WeakReferenceHelper( xStatement ) );
313*cdf0e10cSrcweir 	} catch (sql::SQLException & e) {
314*cdf0e10cSrcweir 		mysqlc_sdbc_driver::translateAndThrow(e, *this, getConnectionEncoding());
315*cdf0e10cSrcweir 	}
316*cdf0e10cSrcweir 	return xStatement;
317*cdf0e10cSrcweir }
318*cdf0e10cSrcweir /* }}} */
319*cdf0e10cSrcweir 
320*cdf0e10cSrcweir 
321*cdf0e10cSrcweir /* {{{ OConnection::prepareCall() -U- */
322*cdf0e10cSrcweir Reference< XPreparedStatement > SAL_CALL OConnection::prepareCall(const OUString& /*_sSql*/ )
323*cdf0e10cSrcweir 	throw(SQLException, RuntimeException)
324*cdf0e10cSrcweir {
325*cdf0e10cSrcweir 	OSL_TRACE("OConnection::prepareCall");
326*cdf0e10cSrcweir 	MutexGuard aGuard(m_aMutex);
327*cdf0e10cSrcweir 	checkDisposed(OConnection_BASE::rBHelper.bDisposed);
328*cdf0e10cSrcweir 
329*cdf0e10cSrcweir 	mysqlc_sdbc_driver::throwFeatureNotImplementedException("OConnection::prepareCall", *this);
330*cdf0e10cSrcweir 	return Reference< XPreparedStatement >();
331*cdf0e10cSrcweir }
332*cdf0e10cSrcweir /* }}} */
333*cdf0e10cSrcweir 
334*cdf0e10cSrcweir 
335*cdf0e10cSrcweir /* {{{ OConnection::nativeSQL() -I- */
336*cdf0e10cSrcweir OUString SAL_CALL OConnection::nativeSQL(const OUString& _sSql)
337*cdf0e10cSrcweir 	throw(SQLException, RuntimeException)
338*cdf0e10cSrcweir {
339*cdf0e10cSrcweir 	OSL_TRACE("OConnection::nativeSQL");
340*cdf0e10cSrcweir 	MutexGuard aGuard(m_aMutex);
341*cdf0e10cSrcweir 
342*cdf0e10cSrcweir 	const ::rtl::OUString sSqlStatement = transFormPreparedStatement( _sSql );
343*cdf0e10cSrcweir     ::rtl::OUString sNativeSQL;
344*cdf0e10cSrcweir 	try {
345*cdf0e10cSrcweir 		sNativeSQL = mysqlc_sdbc_driver::convert(m_settings.cppConnection->nativeSQL(mysqlc_sdbc_driver::convert(sSqlStatement, getConnectionEncoding())),
346*cdf0e10cSrcweir 																				getConnectionEncoding());
347*cdf0e10cSrcweir 	} catch (sql::SQLException & e) {
348*cdf0e10cSrcweir 		mysqlc_sdbc_driver::translateAndThrow(e, *this, getConnectionEncoding());
349*cdf0e10cSrcweir 	}
350*cdf0e10cSrcweir     return sNativeSQL;
351*cdf0e10cSrcweir }
352*cdf0e10cSrcweir /* }}} */
353*cdf0e10cSrcweir 
354*cdf0e10cSrcweir 
355*cdf0e10cSrcweir /* {{{ OConnection::setAutoCommit() -I- */
356*cdf0e10cSrcweir void SAL_CALL OConnection::setAutoCommit(sal_Bool autoCommit)
357*cdf0e10cSrcweir 	throw(SQLException, RuntimeException)
358*cdf0e10cSrcweir {
359*cdf0e10cSrcweir 	OSL_TRACE("OConnection::setAutoCommit");
360*cdf0e10cSrcweir 	MutexGuard aGuard(m_aMutex);
361*cdf0e10cSrcweir 	checkDisposed(OConnection_BASE::rBHelper.bDisposed);
362*cdf0e10cSrcweir 	try {
363*cdf0e10cSrcweir 		m_settings.cppConnection->setAutoCommit(autoCommit == sal_True? true:false);
364*cdf0e10cSrcweir 	} catch (sql::SQLException & e) {
365*cdf0e10cSrcweir 		mysqlc_sdbc_driver::translateAndThrow(e, *this, getConnectionEncoding());
366*cdf0e10cSrcweir 	}
367*cdf0e10cSrcweir }
368*cdf0e10cSrcweir /* }}} */
369*cdf0e10cSrcweir 
370*cdf0e10cSrcweir 
371*cdf0e10cSrcweir /* {{{ OConnection::getAutoCommit() -I- */
372*cdf0e10cSrcweir sal_Bool SAL_CALL OConnection::getAutoCommit()
373*cdf0e10cSrcweir 	throw(SQLException, RuntimeException)
374*cdf0e10cSrcweir {
375*cdf0e10cSrcweir 	OSL_TRACE("OConnection::getAutoCommit");
376*cdf0e10cSrcweir 	// you have to distinguish which if you are in autocommit mode or not
377*cdf0e10cSrcweir 	// at normal case true should be fine here
378*cdf0e10cSrcweir 
379*cdf0e10cSrcweir 	MutexGuard aGuard(m_aMutex);
380*cdf0e10cSrcweir 	checkDisposed(OConnection_BASE::rBHelper.bDisposed);
381*cdf0e10cSrcweir 
382*cdf0e10cSrcweir 	sal_Bool autoCommit = sal_False;
383*cdf0e10cSrcweir 	try {
384*cdf0e10cSrcweir 		autoCommit = m_settings.cppConnection->getAutoCommit() == true ? sal_True : sal_False;
385*cdf0e10cSrcweir 	} catch (sql::SQLException & e) {
386*cdf0e10cSrcweir 		mysqlc_sdbc_driver::translateAndThrow(e, *this, getConnectionEncoding());
387*cdf0e10cSrcweir 	}
388*cdf0e10cSrcweir 	return autoCommit;
389*cdf0e10cSrcweir }
390*cdf0e10cSrcweir /* }}} */
391*cdf0e10cSrcweir 
392*cdf0e10cSrcweir 
393*cdf0e10cSrcweir /* {{{ OConnection::commit() -I- */
394*cdf0e10cSrcweir void SAL_CALL OConnection::commit()
395*cdf0e10cSrcweir 	throw(SQLException, RuntimeException)
396*cdf0e10cSrcweir {
397*cdf0e10cSrcweir 	OSL_TRACE("OConnection::commit");
398*cdf0e10cSrcweir 	MutexGuard aGuard(m_aMutex);
399*cdf0e10cSrcweir 	checkDisposed(OConnection_BASE::rBHelper.bDisposed);
400*cdf0e10cSrcweir 	try {
401*cdf0e10cSrcweir 		m_settings.cppConnection->commit();
402*cdf0e10cSrcweir 	} catch (sql::SQLException & e) {
403*cdf0e10cSrcweir 		mysqlc_sdbc_driver::translateAndThrow(e, *this, getConnectionEncoding());
404*cdf0e10cSrcweir 	}
405*cdf0e10cSrcweir }
406*cdf0e10cSrcweir /* }}} */
407*cdf0e10cSrcweir 
408*cdf0e10cSrcweir 
409*cdf0e10cSrcweir /* {{{ OConnection::rollback() -I- */
410*cdf0e10cSrcweir void SAL_CALL OConnection::rollback()
411*cdf0e10cSrcweir 	throw(SQLException, RuntimeException)
412*cdf0e10cSrcweir {
413*cdf0e10cSrcweir 	OSL_TRACE("OConnection::rollback");
414*cdf0e10cSrcweir 	MutexGuard aGuard(m_aMutex);
415*cdf0e10cSrcweir 	checkDisposed(OConnection_BASE::rBHelper.bDisposed);
416*cdf0e10cSrcweir 	try {
417*cdf0e10cSrcweir 		m_settings.cppConnection->rollback();
418*cdf0e10cSrcweir 	} catch (sql::SQLException & e) {
419*cdf0e10cSrcweir 		mysqlc_sdbc_driver::translateAndThrow(e, *this, getConnectionEncoding());
420*cdf0e10cSrcweir 	}
421*cdf0e10cSrcweir }
422*cdf0e10cSrcweir /* }}} */
423*cdf0e10cSrcweir 
424*cdf0e10cSrcweir 
425*cdf0e10cSrcweir /* {{{ OConnection::isClosed() -I- */
426*cdf0e10cSrcweir sal_Bool SAL_CALL OConnection::isClosed()
427*cdf0e10cSrcweir 	throw(SQLException, RuntimeException)
428*cdf0e10cSrcweir {
429*cdf0e10cSrcweir 	OSL_TRACE("OConnection::isClosed");
430*cdf0e10cSrcweir 	MutexGuard aGuard(m_aMutex);
431*cdf0e10cSrcweir 
432*cdf0e10cSrcweir 	// just simple -> we are close when we are disposed taht means someone called dispose(); (XComponent)
433*cdf0e10cSrcweir 	return (OConnection_BASE::rBHelper.bDisposed);
434*cdf0e10cSrcweir }
435*cdf0e10cSrcweir /* }}} */
436*cdf0e10cSrcweir 
437*cdf0e10cSrcweir 
438*cdf0e10cSrcweir /* {{{ OConnection::createStatement() -I- */
439*cdf0e10cSrcweir Reference< XDatabaseMetaData > SAL_CALL OConnection::getMetaData()
440*cdf0e10cSrcweir 	throw(SQLException, RuntimeException)
441*cdf0e10cSrcweir {
442*cdf0e10cSrcweir 	OSL_TRACE("OConnection::getMetaData");
443*cdf0e10cSrcweir 	MutexGuard aGuard(m_aMutex);
444*cdf0e10cSrcweir 	checkDisposed(OConnection_BASE::rBHelper.bDisposed);
445*cdf0e10cSrcweir 
446*cdf0e10cSrcweir 	Reference< XDatabaseMetaData > xMetaData = m_xMetaData;
447*cdf0e10cSrcweir 	if (!xMetaData.is()) {
448*cdf0e10cSrcweir 		try {
449*cdf0e10cSrcweir 			xMetaData = new ODatabaseMetaData(*this); // need the connection because it can return it
450*cdf0e10cSrcweir 		} catch (sql::SQLException & e) {
451*cdf0e10cSrcweir 			mysqlc_sdbc_driver::translateAndThrow(e, *this, getConnectionEncoding());
452*cdf0e10cSrcweir 		}
453*cdf0e10cSrcweir 		m_xMetaData = xMetaData;
454*cdf0e10cSrcweir 	}
455*cdf0e10cSrcweir 
456*cdf0e10cSrcweir 	return xMetaData;
457*cdf0e10cSrcweir }
458*cdf0e10cSrcweir /* }}} */
459*cdf0e10cSrcweir 
460*cdf0e10cSrcweir 
461*cdf0e10cSrcweir /* {{{ OConnection::createStatement() -I- */
462*cdf0e10cSrcweir void SAL_CALL OConnection::setReadOnly(sal_Bool readOnly)
463*cdf0e10cSrcweir 	throw(SQLException, RuntimeException)
464*cdf0e10cSrcweir {
465*cdf0e10cSrcweir 	OSL_TRACE("OConnection::setReadOnly");
466*cdf0e10cSrcweir 	MutexGuard aGuard(m_aMutex);
467*cdf0e10cSrcweir 	checkDisposed(OConnection_BASE::rBHelper.bDisposed);
468*cdf0e10cSrcweir 
469*cdf0e10cSrcweir 	m_settings.readOnly = readOnly;
470*cdf0e10cSrcweir }
471*cdf0e10cSrcweir /* }}} */
472*cdf0e10cSrcweir 
473*cdf0e10cSrcweir 
474*cdf0e10cSrcweir /* {{{ OConnection::createStatement() -I- */
475*cdf0e10cSrcweir sal_Bool SAL_CALL OConnection::isReadOnly()
476*cdf0e10cSrcweir 	throw(SQLException, RuntimeException)
477*cdf0e10cSrcweir {
478*cdf0e10cSrcweir 	OSL_TRACE("OConnection::isReadOnly");
479*cdf0e10cSrcweir 	MutexGuard aGuard(m_aMutex);
480*cdf0e10cSrcweir 	checkDisposed(OConnection_BASE::rBHelper.bDisposed);
481*cdf0e10cSrcweir 
482*cdf0e10cSrcweir 	// return if your connection to readonly
483*cdf0e10cSrcweir 	return (m_settings.readOnly);
484*cdf0e10cSrcweir }
485*cdf0e10cSrcweir /* }}} */
486*cdf0e10cSrcweir 
487*cdf0e10cSrcweir 
488*cdf0e10cSrcweir /* {{{ OConnection::createStatement() -I- */
489*cdf0e10cSrcweir void SAL_CALL OConnection::setCatalog(const OUString& catalog)
490*cdf0e10cSrcweir 	throw(SQLException, RuntimeException)
491*cdf0e10cSrcweir {
492*cdf0e10cSrcweir 	OSL_TRACE("OConnection::setCatalog");
493*cdf0e10cSrcweir 	MutexGuard aGuard(m_aMutex);
494*cdf0e10cSrcweir 	checkDisposed(OConnection_BASE::rBHelper.bDisposed);
495*cdf0e10cSrcweir 
496*cdf0e10cSrcweir 	try {
497*cdf0e10cSrcweir //		m_settings.cppConnection->setCatalog(OUStringToOString(catalog, m_settings.encoding).getStr());
498*cdf0e10cSrcweir 		m_settings.cppConnection->setSchema(OUStringToOString(catalog, getConnectionEncoding()).getStr());
499*cdf0e10cSrcweir 	} catch (sql::SQLException & e) {
500*cdf0e10cSrcweir 		mysqlc_sdbc_driver::translateAndThrow(e, *this, getConnectionEncoding());
501*cdf0e10cSrcweir 	}
502*cdf0e10cSrcweir }
503*cdf0e10cSrcweir /* }}} */
504*cdf0e10cSrcweir 
505*cdf0e10cSrcweir 
506*cdf0e10cSrcweir /* {{{ OConnection::createStatement() -I- */
507*cdf0e10cSrcweir OUString SAL_CALL OConnection::getCatalog()
508*cdf0e10cSrcweir 	throw(SQLException, RuntimeException)
509*cdf0e10cSrcweir {
510*cdf0e10cSrcweir 	OSL_TRACE("OConnection::getCatalog");
511*cdf0e10cSrcweir 	MutexGuard aGuard(m_aMutex);
512*cdf0e10cSrcweir 	checkDisposed(OConnection_BASE::rBHelper.bDisposed);
513*cdf0e10cSrcweir 
514*cdf0e10cSrcweir 	OUString catalog;
515*cdf0e10cSrcweir 	try {
516*cdf0e10cSrcweir 		catalog = mysqlc_sdbc_driver::convert(m_settings.cppConnection->getSchema(), getConnectionEncoding());
517*cdf0e10cSrcweir 	} catch (sql::SQLException & e) {
518*cdf0e10cSrcweir 		mysqlc_sdbc_driver::translateAndThrow(e, *this, getConnectionEncoding());
519*cdf0e10cSrcweir 	}
520*cdf0e10cSrcweir 	return catalog;
521*cdf0e10cSrcweir }
522*cdf0e10cSrcweir /* }}} */
523*cdf0e10cSrcweir 
524*cdf0e10cSrcweir 
525*cdf0e10cSrcweir /* {{{ OConnection::createStatement() -I- */
526*cdf0e10cSrcweir void SAL_CALL OConnection::setTransactionIsolation(sal_Int32 level)
527*cdf0e10cSrcweir 	throw(SQLException, RuntimeException)
528*cdf0e10cSrcweir {
529*cdf0e10cSrcweir 	OSL_TRACE("OConnection::setTransactionIsolation");
530*cdf0e10cSrcweir 	MutexGuard aGuard(m_aMutex);
531*cdf0e10cSrcweir 	checkDisposed(OConnection_BASE::rBHelper.bDisposed);
532*cdf0e10cSrcweir 
533*cdf0e10cSrcweir 	sql::enum_transaction_isolation cpplevel = sql::TRANSACTION_SERIALIZABLE;
534*cdf0e10cSrcweir 
535*cdf0e10cSrcweir 	switch (level) {
536*cdf0e10cSrcweir 		case TransactionIsolation::READ_UNCOMMITTED:
537*cdf0e10cSrcweir 			cpplevel = sql::TRANSACTION_READ_UNCOMMITTED;
538*cdf0e10cSrcweir 			break;
539*cdf0e10cSrcweir 		case TransactionIsolation::READ_COMMITTED:
540*cdf0e10cSrcweir 			cpplevel = sql::TRANSACTION_READ_COMMITTED;
541*cdf0e10cSrcweir 			break;
542*cdf0e10cSrcweir 		case TransactionIsolation::REPEATABLE_READ:
543*cdf0e10cSrcweir 			cpplevel = sql::TRANSACTION_REPEATABLE_READ;
544*cdf0e10cSrcweir 			break;
545*cdf0e10cSrcweir 		case TransactionIsolation::SERIALIZABLE:
546*cdf0e10cSrcweir 			cpplevel = sql::TRANSACTION_SERIALIZABLE;
547*cdf0e10cSrcweir 			break;
548*cdf0e10cSrcweir 		case TransactionIsolation::NONE:
549*cdf0e10cSrcweir 			cpplevel = sql::TRANSACTION_SERIALIZABLE;
550*cdf0e10cSrcweir 			break;
551*cdf0e10cSrcweir 		default:;
552*cdf0e10cSrcweir 			/* XXX: Exception ?? */
553*cdf0e10cSrcweir 	}
554*cdf0e10cSrcweir 	try {
555*cdf0e10cSrcweir 		m_settings.cppConnection->setTransactionIsolation(cpplevel);
556*cdf0e10cSrcweir 	} catch (sql::SQLException & e) {
557*cdf0e10cSrcweir 		mysqlc_sdbc_driver::translateAndThrow(e, *this, getConnectionEncoding());
558*cdf0e10cSrcweir 	}
559*cdf0e10cSrcweir }
560*cdf0e10cSrcweir /* }}} */
561*cdf0e10cSrcweir 
562*cdf0e10cSrcweir 
563*cdf0e10cSrcweir /* {{{ OConnection::createStatement() -I- */
564*cdf0e10cSrcweir sal_Int32 SAL_CALL OConnection::getTransactionIsolation()
565*cdf0e10cSrcweir 	throw(SQLException, RuntimeException)
566*cdf0e10cSrcweir {
567*cdf0e10cSrcweir 	OSL_TRACE("OConnection::getTransactionIsolation");
568*cdf0e10cSrcweir 	MutexGuard aGuard(m_aMutex);
569*cdf0e10cSrcweir 	checkDisposed(OConnection_BASE::rBHelper.bDisposed);
570*cdf0e10cSrcweir 
571*cdf0e10cSrcweir 	try {
572*cdf0e10cSrcweir 		switch (m_settings.cppConnection->getTransactionIsolation()) {
573*cdf0e10cSrcweir 			case sql::TRANSACTION_SERIALIZABLE:		return TransactionIsolation::SERIALIZABLE;
574*cdf0e10cSrcweir 			case sql::TRANSACTION_REPEATABLE_READ:	return TransactionIsolation::REPEATABLE_READ;
575*cdf0e10cSrcweir 			case sql::TRANSACTION_READ_COMMITTED:	return TransactionIsolation::READ_COMMITTED;
576*cdf0e10cSrcweir 			case sql::TRANSACTION_READ_UNCOMMITTED:	return TransactionIsolation::READ_UNCOMMITTED;
577*cdf0e10cSrcweir 			default:
578*cdf0e10cSrcweir 				;
579*cdf0e10cSrcweir 		}
580*cdf0e10cSrcweir 	} catch (sql::SQLException & e) {
581*cdf0e10cSrcweir 		mysqlc_sdbc_driver::translateAndThrow(e, *this, getConnectionEncoding());
582*cdf0e10cSrcweir 	}
583*cdf0e10cSrcweir 	return TransactionIsolation::NONE;
584*cdf0e10cSrcweir }
585*cdf0e10cSrcweir /* }}} */
586*cdf0e10cSrcweir 
587*cdf0e10cSrcweir 
588*cdf0e10cSrcweir /* {{{ OConnection::getTypeMap() -I- */
589*cdf0e10cSrcweir Reference<XNameAccess> SAL_CALL OConnection::getTypeMap()
590*cdf0e10cSrcweir 	throw(SQLException, RuntimeException)
591*cdf0e10cSrcweir {
592*cdf0e10cSrcweir 	OSL_TRACE("OConnection::getTypeMap");
593*cdf0e10cSrcweir 	MutexGuard aGuard(m_aMutex);
594*cdf0e10cSrcweir 	checkDisposed(OConnection_BASE::rBHelper.bDisposed);
595*cdf0e10cSrcweir 
596*cdf0e10cSrcweir 	Reference<XNameAccess > t;
597*cdf0e10cSrcweir 	{
598*cdf0e10cSrcweir 		t = m_typeMap;
599*cdf0e10cSrcweir 	}
600*cdf0e10cSrcweir 	return (t);
601*cdf0e10cSrcweir }
602*cdf0e10cSrcweir /* }}} */
603*cdf0e10cSrcweir 
604*cdf0e10cSrcweir 
605*cdf0e10cSrcweir /* {{{ OConnection::setTypeMap() -I- */
606*cdf0e10cSrcweir void SAL_CALL OConnection::setTypeMap(const Reference<XNameAccess >& typeMap)
607*cdf0e10cSrcweir 	throw(SQLException, RuntimeException)
608*cdf0e10cSrcweir {
609*cdf0e10cSrcweir 	OSL_TRACE("OConnection::setTypeMap");
610*cdf0e10cSrcweir 	MutexGuard aGuard(m_aMutex);
611*cdf0e10cSrcweir 	checkDisposed(OConnection_BASE::rBHelper.bDisposed);
612*cdf0e10cSrcweir 
613*cdf0e10cSrcweir 	m_typeMap = typeMap;
614*cdf0e10cSrcweir }
615*cdf0e10cSrcweir /* }}} */
616*cdf0e10cSrcweir 
617*cdf0e10cSrcweir 
618*cdf0e10cSrcweir // XCloseable
619*cdf0e10cSrcweir /* {{{ OConnection::close() -I- */
620*cdf0e10cSrcweir void SAL_CALL OConnection::close()
621*cdf0e10cSrcweir 	throw(SQLException, RuntimeException)
622*cdf0e10cSrcweir {
623*cdf0e10cSrcweir 	OSL_TRACE("OConnection::close");
624*cdf0e10cSrcweir 	/*
625*cdf0e10cSrcweir 	  we need block, because the mutex is a local variable,
626*cdf0e10cSrcweir 	  which will guard the block
627*cdf0e10cSrcweir 	*/
628*cdf0e10cSrcweir 	{
629*cdf0e10cSrcweir 		// we just dispose us
630*cdf0e10cSrcweir 		MutexGuard aGuard(m_aMutex);
631*cdf0e10cSrcweir 		checkDisposed(OConnection_BASE::rBHelper.bDisposed);
632*cdf0e10cSrcweir 	}
633*cdf0e10cSrcweir 	dispose();
634*cdf0e10cSrcweir }
635*cdf0e10cSrcweir /* }}} */
636*cdf0e10cSrcweir 
637*cdf0e10cSrcweir 
638*cdf0e10cSrcweir // XWarningsSupplier
639*cdf0e10cSrcweir /* {{{ OConnection::getWarnings() -I- */
640*cdf0e10cSrcweir Any SAL_CALL OConnection::getWarnings()
641*cdf0e10cSrcweir 	throw(SQLException, RuntimeException)
642*cdf0e10cSrcweir {
643*cdf0e10cSrcweir 	Any x = Any();
644*cdf0e10cSrcweir 	OSL_TRACE("OConnection::getWarnings");
645*cdf0e10cSrcweir 	// when you collected some warnings -> return it
646*cdf0e10cSrcweir 	return x;
647*cdf0e10cSrcweir }
648*cdf0e10cSrcweir /* }}} */
649*cdf0e10cSrcweir 
650*cdf0e10cSrcweir 
651*cdf0e10cSrcweir /* {{{ OConnection::clearWarnings() -I- */
652*cdf0e10cSrcweir void SAL_CALL OConnection::clearWarnings()
653*cdf0e10cSrcweir 	throw(SQLException, RuntimeException)
654*cdf0e10cSrcweir {
655*cdf0e10cSrcweir 	OSL_TRACE("OConnection::clearWarnings");
656*cdf0e10cSrcweir 	// you should clear your collected warnings here#
657*cdf0e10cSrcweir }
658*cdf0e10cSrcweir /* }}} */
659*cdf0e10cSrcweir 
660*cdf0e10cSrcweir 
661*cdf0e10cSrcweir /* {{{ OConnection::buildTypeInfo() -I- */
662*cdf0e10cSrcweir void OConnection::buildTypeInfo()
663*cdf0e10cSrcweir 	throw(SQLException)
664*cdf0e10cSrcweir {
665*cdf0e10cSrcweir 	OSL_TRACE("OConnection::buildTypeInfo");
666*cdf0e10cSrcweir }
667*cdf0e10cSrcweir /* }}} */
668*cdf0e10cSrcweir 
669*cdf0e10cSrcweir 
670*cdf0e10cSrcweir /* {{{ OConnection::disposing() -I- */
671*cdf0e10cSrcweir void OConnection::disposing()
672*cdf0e10cSrcweir {
673*cdf0e10cSrcweir 	OSL_TRACE("OConnection::disposing");
674*cdf0e10cSrcweir 	// we noticed that we should be destroied in near future so we have to dispose our statements
675*cdf0e10cSrcweir 	MutexGuard aGuard(m_aMutex);
676*cdf0e10cSrcweir 
677*cdf0e10cSrcweir 	for (OWeakRefArray::iterator i = m_aStatements.begin(); i != m_aStatements.end() ; ++i) {
678*cdf0e10cSrcweir 		Reference< XComponent > xComp(i->get(), UNO_QUERY);
679*cdf0e10cSrcweir 		if (xComp.is()) {
680*cdf0e10cSrcweir 			xComp->dispose();
681*cdf0e10cSrcweir 		}
682*cdf0e10cSrcweir 	}
683*cdf0e10cSrcweir 	m_aStatements.clear();
684*cdf0e10cSrcweir 
685*cdf0e10cSrcweir 	m_bClosed	= sal_True;
686*cdf0e10cSrcweir 	m_xMetaData	= WeakReference< XDatabaseMetaData >();
687*cdf0e10cSrcweir 
688*cdf0e10cSrcweir 	dispose_ChildImpl();
689*cdf0e10cSrcweir 	OConnection_BASE::disposing();
690*cdf0e10cSrcweir }
691*cdf0e10cSrcweir /* }}} */
692*cdf0e10cSrcweir 
693*cdf0e10cSrcweir 
694*cdf0e10cSrcweir /* ToDo - upcast the connection to MySQL_Connection and use ::getSessionVariable() */
695*cdf0e10cSrcweir 
696*cdf0e10cSrcweir /* {{{ OConnection::getMysqlVariable() -I- */
697*cdf0e10cSrcweir OUString OConnection::getMysqlVariable(const char *varname)
698*cdf0e10cSrcweir 	throw(SQLException, RuntimeException)
699*cdf0e10cSrcweir {
700*cdf0e10cSrcweir 	OSL_TRACE("OConnection::getMysqlVariable");
701*cdf0e10cSrcweir 	MutexGuard aGuard(m_aMutex);
702*cdf0e10cSrcweir 	checkDisposed(OConnection_BASE::rBHelper.bDisposed);
703*cdf0e10cSrcweir 
704*cdf0e10cSrcweir 	OUString ret;
705*cdf0e10cSrcweir 	::rtl::OUStringBuffer aStatement;
706*cdf0e10cSrcweir 	aStatement.appendAscii( "SHOW SESSION VARIABLES LIKE '" );
707*cdf0e10cSrcweir 	aStatement.appendAscii( varname );
708*cdf0e10cSrcweir 	aStatement.append( sal_Unicode( '\'' ) );
709*cdf0e10cSrcweir 
710*cdf0e10cSrcweir 	try {
711*cdf0e10cSrcweir 		XStatement * stmt = new OStatement(this, m_settings.cppConnection->createStatement());
712*cdf0e10cSrcweir 		Reference< XResultSet > rs = stmt->executeQuery( aStatement.makeStringAndClear() );
713*cdf0e10cSrcweir 		if (rs.is() && rs->next()) {
714*cdf0e10cSrcweir 			Reference< XRow > xRow(rs, UNO_QUERY);
715*cdf0e10cSrcweir 			ret = xRow->getString(2);
716*cdf0e10cSrcweir 		}
717*cdf0e10cSrcweir 	} catch (sql::SQLException & e) {
718*cdf0e10cSrcweir 		mysqlc_sdbc_driver::translateAndThrow(e, *this, getConnectionEncoding());
719*cdf0e10cSrcweir 	}
720*cdf0e10cSrcweir 
721*cdf0e10cSrcweir 	return ret;
722*cdf0e10cSrcweir }
723*cdf0e10cSrcweir /* }}} */
724*cdf0e10cSrcweir 
725*cdf0e10cSrcweir 
726*cdf0e10cSrcweir /* {{{ OConnection::getMysqlVersion() -I- */
727*cdf0e10cSrcweir sal_Int32 OConnection::getMysqlVersion()
728*cdf0e10cSrcweir 	throw(SQLException, RuntimeException)
729*cdf0e10cSrcweir {
730*cdf0e10cSrcweir 	OSL_TRACE("OConnection::getMysqlVersion");
731*cdf0e10cSrcweir 	MutexGuard aGuard(m_aMutex);
732*cdf0e10cSrcweir 	checkDisposed(OConnection_BASE::rBHelper.bDisposed);
733*cdf0e10cSrcweir 
734*cdf0e10cSrcweir 	sal_Int32 version(0);
735*cdf0e10cSrcweir 	try {
736*cdf0e10cSrcweir 		version = 10000 * m_settings.cppConnection->getMetaData()->getDatabaseMajorVersion();
737*cdf0e10cSrcweir 		version += 100 * m_settings.cppConnection->getMetaData()->getDatabaseMinorVersion();
738*cdf0e10cSrcweir 		version += m_settings.cppConnection->getMetaData()->getDatabasePatchVersion();
739*cdf0e10cSrcweir 	} catch (sql::SQLException & e) {
740*cdf0e10cSrcweir 		mysqlc_sdbc_driver::translateAndThrow(e, *this, getConnectionEncoding());
741*cdf0e10cSrcweir 	}
742*cdf0e10cSrcweir 	return version;
743*cdf0e10cSrcweir }
744*cdf0e10cSrcweir /* }}} */
745*cdf0e10cSrcweir 
746*cdf0e10cSrcweir 
747*cdf0e10cSrcweir /* {{{ OConnection::sdbcColumnType() -I- */
748*cdf0e10cSrcweir // TODO: Not used
749*cdf0e10cSrcweir //sal_Int32 OConnection::sdbcColumnType(OUString typeName)
750*cdf0e10cSrcweir //{
751*cdf0e10cSrcweir //	OSL_TRACE("OConnection::sdbcColumnType");
752*cdf0e10cSrcweir //	int i = 0;
753*cdf0e10cSrcweir //	while (mysqlc_types[i].typeName) {
754*cdf0e10cSrcweir //		if (OUString::createFromAscii(mysqlc_types[i].typeName).equals(
755*cdf0e10cSrcweir //			typeName.toAsciiUpperCase()))
756*cdf0e10cSrcweir //		{
757*cdf0e10cSrcweir //			return mysqlc_types[i].dataType;
758*cdf0e10cSrcweir //		}
759*cdf0e10cSrcweir //		i++;
760*cdf0e10cSrcweir //	}
761*cdf0e10cSrcweir //	return 0;
762*cdf0e10cSrcweir //}
763*cdf0e10cSrcweir // -----------------------------------------------------------------------------
764*cdf0e10cSrcweir ::rtl::OUString OConnection::transFormPreparedStatement(const ::rtl::OUString& _sSQL)
765*cdf0e10cSrcweir {
766*cdf0e10cSrcweir 	::rtl::OUString sSqlStatement = _sSQL;
767*cdf0e10cSrcweir 	if ( !m_xParameterSubstitution.is() ) {
768*cdf0e10cSrcweir 		try {
769*cdf0e10cSrcweir 			Sequence< Any > aArgs(1);
770*cdf0e10cSrcweir 			Reference< XConnection> xCon = this;
771*cdf0e10cSrcweir 			aArgs[0] <<= NamedValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ActiveConnection")), makeAny(xCon));
772*cdf0e10cSrcweir 
773*cdf0e10cSrcweir 			m_xParameterSubstitution.set(m_rDriver.getFactory()->createInstanceWithArguments(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("org.openoffice.comp.helper.ParameterSubstitution")),aArgs),UNO_QUERY);
774*cdf0e10cSrcweir 		} catch(const Exception&) {}
775*cdf0e10cSrcweir 	}
776*cdf0e10cSrcweir 	if ( m_xParameterSubstitution.is() ) {
777*cdf0e10cSrcweir 		try	{
778*cdf0e10cSrcweir 			sSqlStatement = m_xParameterSubstitution->substituteVariables(sSqlStatement,sal_True);
779*cdf0e10cSrcweir 		} catch(const Exception&) { }
780*cdf0e10cSrcweir 	}
781*cdf0e10cSrcweir 	return sSqlStatement;
782*cdf0e10cSrcweir }
783*cdf0e10cSrcweir 
784*cdf0e10cSrcweir /* }}} */
785*cdf0e10cSrcweir 
786*cdf0e10cSrcweir /*
787*cdf0e10cSrcweir  * Local variables:
788*cdf0e10cSrcweir  * tab-width: 4
789*cdf0e10cSrcweir  * c-basic-offset: 4
790*cdf0e10cSrcweir  * End:
791*cdf0e10cSrcweir  * vim600: noet sw=4 ts=4 fdm=marker
792*cdf0e10cSrcweir  * vim<600: noet sw=4 ts=4
793*cdf0e10cSrcweir  */
794