bump product version to 5.0.4.1
[LibreOffice.git] / mysqlc / source / mysqlc_connection.cxx
blobd6a8fe416dd46be6470e7fe649b96e53c85019df
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "mysqlc_connection.hxx"
21 #include "mysqlc_databasemetadata.hxx"
24 #include "mysqlc_driver.hxx"
25 #include "mysqlc_statement.hxx"
26 #include "mysqlc_preparedstatement.hxx"
27 #include "mysqlc_general.hxx"
29 #include <cppconn/driver.h>
30 #include <cppconn/connection.h>
31 #include <cppconn/statement.h>
32 #include <cppconn/metadata.h>
33 #include <cppconn/exception.h>
35 #include <com/sun/star/sdbc/ColumnValue.hpp>
36 #include <com/sun/star/sdbc/XRow.hpp>
37 #include <com/sun/star/sdbc/TransactionIsolation.hpp>
38 #include <com/sun/star/lang/DisposedException.hpp>
39 #include <com/sun/star/beans/NamedValue.hpp>
41 #include <osl/module.hxx>
42 #include <osl/thread.h>
43 #include <osl/file.h>
44 #include <rtl/uri.hxx>
45 #include <rtl/ustrbuf.hxx>
47 using namespace connectivity::mysqlc;
49 #include <stdio.h>
52 using namespace com::sun::star::uno;
53 using namespace com::sun::star::container;
54 using namespace com::sun::star::lang;
55 using namespace com::sun::star::beans;
56 using namespace com::sun::star::sdbc;
57 using ::osl::MutexGuard;
60 #define MYSQLC_URI_PREFIX "sdbc:mysqlc:"
63 OConnection::OConnection(MysqlCDriver& _rDriver, sql::Driver * _cppDriver)
64 :OMetaConnection_BASE(m_aMutex)
65 ,OSubComponent<OConnection, OConnection_BASE>((::cppu::OWeakObject*)&_rDriver, this)
66 ,m_xMetaData(NULL)
67 ,m_rDriver(_rDriver)
68 ,cppDriver(_cppDriver)
69 ,m_bClosed(false)
70 ,m_bUseCatalog(false)
71 ,m_bUseOldDateFormat(false)
73 OSL_TRACE("OConnection::OConnection");
74 m_rDriver.acquire();
77 OConnection::~OConnection()
79 OSL_TRACE("OConnection::~OConnection");
80 if (!isClosed()) {
81 close();
83 m_rDriver.release();
86 void SAL_CALL OConnection::release()
87 throw()
89 OSL_TRACE("OConnection::release");
90 relase_ChildImpl();
93 void OConnection::construct(const rtl::OUString& url, const Sequence< PropertyValue >& info)
94 throw(SQLException)
96 OSL_TRACE("OConnection::construct");
97 MutexGuard aGuard(m_aMutex);
99 sal_Int32 nIndex;
100 bool bEmbedded = false;
101 rtl::OUString token;
102 rtl::OUString aHostName("localhost");
103 sal_Int32 nPort = 3306;
104 rtl::OUString aDbName;
106 m_settings.encoding = MysqlCDriver::getDefaultEncoding();
107 m_settings.quoteIdentifier.clear();
109 // parse url. Url has the following format:
110 // external server: sdbc:mysqlc:[hostname]:[port]/[dbname]
112 if (url.startsWith(MYSQLC_URI_PREFIX)) {
113 nIndex = 12;
114 } else {
115 bEmbedded = true;
116 nIndex = 20;
117 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OConnection::construct (embedded MySQL)", *this);
120 token = url.getToken(0, '/', nIndex);
121 if (!token.isEmpty()) {
122 sal_Int32 nIndex1 = 0;
123 rtl::OUString hostandport = token.getToken(0,':', nIndex1);
124 if (!hostandport.isEmpty()) {
125 aHostName = hostandport;
126 hostandport = token.getToken(0, ':', nIndex1);
127 if (!hostandport.isEmpty() && nIndex1) {
128 nPort = hostandport.toInt32();
130 token = url.getToken(0, '/', nIndex);
131 if (!token.isEmpty() && nIndex) {
132 aDbName = token;
137 // get user and password for mysql connection
138 const PropertyValue *pIter = info.getConstArray();
139 const PropertyValue *pEnd = pIter + info.getLength();
140 rtl::OUString aUser, aPass, sUnixSocket, sNamedPipe;
141 bool unixSocketPassed = false;
142 bool namedPipePassed = false;
144 m_settings.connectionURL = url;
145 for (;pIter != pEnd;++pIter) {
146 if (pIter->Name.equalsAscii("user")) {
147 OSL_VERIFY( pIter->Value >>= aUser );
148 } else if (pIter->Name.equalsAscii("password")) {
149 OSL_VERIFY( pIter->Value >>= aPass );
150 } else if (pIter->Name.equalsAscii("LocalSocket")) {
151 OSL_VERIFY( pIter->Value >>= sUnixSocket );
152 unixSocketPassed = !sUnixSocket.isEmpty();
153 } else if (pIter->Name.equalsAscii("NamedPipe")) {
154 OSL_VERIFY( pIter->Value >>= sNamedPipe );
155 namedPipePassed = !sNamedPipe.isEmpty();
156 } else if ( pIter->Name.equalsAscii("PublicConnectionURL")) {
157 OSL_VERIFY( pIter->Value >>= m_settings.connectionURL );
158 } else if ( pIter->Name.equalsAscii("NewURL")) { // legacy name for "PublicConnectionURL"
159 OSL_VERIFY( pIter->Value >>= m_settings.connectionURL );
163 if (!bEmbedded) {
164 try {
165 sql::ConnectOptionsMap connProps;
166 std::string host_str = rtl::OUStringToOString(aHostName, m_settings.encoding).getStr();
167 std::string user_str = rtl::OUStringToOString(aUser, m_settings.encoding).getStr();
168 std::string pass_str = rtl::OUStringToOString(aPass, m_settings.encoding).getStr();
169 std::string schema_str = rtl::OUStringToOString(aDbName, m_settings.encoding).getStr();
170 connProps["hostName"] = sql::ConnectPropertyVal(host_str);
171 connProps["userName"] = sql::ConnectPropertyVal(user_str);
172 connProps["password"] = sql::ConnectPropertyVal(pass_str);
173 connProps["schema"] = sql::ConnectPropertyVal(schema_str);
174 connProps["port"] = sql::ConnectPropertyVal((int)(nPort));
175 if (unixSocketPassed) {
176 sql::SQLString socket_str = rtl::OUStringToOString(sUnixSocket, m_settings.encoding).getStr();
177 connProps["socket"] = socket_str;
178 } else if (namedPipePassed) {
179 sql::SQLString pipe_str = rtl::OUStringToOString(sNamedPipe, m_settings.encoding).getStr();
180 connProps["socket"] = pipe_str;
183 OSL_TRACE("hostName=%s", host_str.c_str());
184 OSL_TRACE("port=%i", int(nPort));
185 OSL_TRACE("userName=%s", user_str.c_str());
186 OSL_TRACE("password=%s", pass_str.c_str());
187 OSL_TRACE("schema=%s", schema_str.c_str());
189 m_settings.cppConnection.reset(cppDriver->connect(connProps));
190 } catch (const sql::SQLException &e) {
191 mysqlc_sdbc_driver::translateAndThrow(e, *this, getConnectionEncoding());
193 } else {
194 // TODO: support for embedded server
197 m_settings.schema = aDbName;
198 OSL_TRACE("%s", rtl::OUStringToOString(m_settings.schema, getConnectionEncoding()).getStr());
200 // Check if the server is 4.1 or above
201 if (this->getMysqlVersion() < 40100) {
202 throw SQLException(
203 "MariaDB LibreOffice Connector requires MySQL Server 4.1 or above",
204 *this,
205 rtl::OUString(),
207 Any());
209 std::unique_ptr<sql::Statement> stmt(m_settings.cppConnection->createStatement());
210 stmt->executeUpdate("SET session sql_mode='ANSI_QUOTES'");
211 stmt->executeUpdate("SET NAMES utf8");
214 rtl::OUString OConnection::getImplementationName() throw (css::uno::RuntimeException, std::exception)
216 return rtl::OUString("com.sun.star.sdbc.drivers.mysqlc.OConnection");
219 css::uno::Sequence<rtl::OUString> OConnection::getSupportedServiceNames()
220 throw (css::uno::RuntimeException, std::exception)
222 css::uno::Sequence<rtl::OUString> s(1);
223 s[0] = "com.sun.star.sdbc.Connection";
224 return s;
227 sal_Bool OConnection::supportsService(rtl::OUString const & ServiceName)
228 throw (css::uno::RuntimeException, std::exception)
230 return cppu::supportsService(this, ServiceName);
233 Reference< XStatement > SAL_CALL OConnection::createStatement()
234 throw(SQLException, RuntimeException, std::exception)
236 OSL_TRACE("OConnection::createStatement");
237 MutexGuard aGuard(m_aMutex);
238 checkDisposed(OConnection_BASE::rBHelper.bDisposed);
240 // create a statement
241 Reference< XStatement > xReturn;
242 // the statement can only be executed once
243 try {
244 xReturn = new OStatement(this, m_settings.cppConnection->createStatement());
245 m_aStatements.push_back(WeakReferenceHelper(xReturn));
246 return xReturn;
247 } catch (const sql::SQLException & e) {
248 mysqlc_sdbc_driver::translateAndThrow(e, *this, getConnectionEncoding());
250 return xReturn;
253 Reference< XPreparedStatement > SAL_CALL OConnection::prepareStatement(const rtl::OUString& _sSql)
254 throw(SQLException, RuntimeException, std::exception)
256 OSL_TRACE("OConnection::prepareStatement");
257 MutexGuard aGuard(m_aMutex);
258 checkDisposed(OConnection_BASE::rBHelper.bDisposed);
259 const rtl::OUString sSqlStatement = transFormPreparedStatement( _sSql );
261 Reference< XPreparedStatement > xStatement;
262 try {
263 // create a statement
264 // the statement can only be executed more than once
265 xStatement = new OPreparedStatement(this,
266 m_settings.cppConnection->prepareStatement(rtl::OUStringToOString(sSqlStatement, getConnectionEncoding()).getStr()));
267 m_aStatements.push_back( WeakReferenceHelper( xStatement ) );
268 } catch (const sql::SQLException & e) {
269 mysqlc_sdbc_driver::translateAndThrow(e, *this, getConnectionEncoding());
271 return xStatement;
274 Reference< XPreparedStatement > SAL_CALL OConnection::prepareCall(const rtl::OUString& /*_sSql*/ )
275 throw(SQLException, RuntimeException, std::exception)
277 OSL_TRACE("OConnection::prepareCall");
278 MutexGuard aGuard(m_aMutex);
279 checkDisposed(OConnection_BASE::rBHelper.bDisposed);
281 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OConnection::prepareCall", *this);
282 return Reference< XPreparedStatement >();
285 rtl::OUString SAL_CALL OConnection::nativeSQL(const rtl::OUString& _sSql)
286 throw(SQLException, RuntimeException, std::exception)
288 OSL_TRACE("OConnection::nativeSQL");
289 MutexGuard aGuard(m_aMutex);
291 const rtl::OUString sSqlStatement = transFormPreparedStatement( _sSql );
292 rtl::OUString sNativeSQL;
293 try {
294 sNativeSQL = mysqlc_sdbc_driver::convert(m_settings.cppConnection->nativeSQL(mysqlc_sdbc_driver::convert(sSqlStatement, getConnectionEncoding())),
295 getConnectionEncoding());
296 } catch (const sql::SQLException & e) {
297 mysqlc_sdbc_driver::translateAndThrow(e, *this, getConnectionEncoding());
299 return sNativeSQL;
302 void SAL_CALL OConnection::setAutoCommit(sal_Bool autoCommit)
303 throw(SQLException, RuntimeException, std::exception)
305 OSL_TRACE("OConnection::setAutoCommit");
306 MutexGuard aGuard(m_aMutex);
307 checkDisposed(OConnection_BASE::rBHelper.bDisposed);
308 try {
309 m_settings.cppConnection->setAutoCommit(autoCommit == sal_True);
310 } catch (const sql::SQLException & e) {
311 mysqlc_sdbc_driver::translateAndThrow(e, *this, getConnectionEncoding());
315 sal_Bool SAL_CALL OConnection::getAutoCommit()
316 throw(SQLException, RuntimeException, std::exception)
318 OSL_TRACE("OConnection::getAutoCommit");
319 // you have to distinguish which if you are in autocommit mode or not
320 // at normal case true should be fine here
322 MutexGuard aGuard(m_aMutex);
323 checkDisposed(OConnection_BASE::rBHelper.bDisposed);
325 bool autoCommit = false;
326 try {
327 autoCommit = m_settings.cppConnection->getAutoCommit();
328 } catch (const sql::SQLException & e) {
329 mysqlc_sdbc_driver::translateAndThrow(e, *this, getConnectionEncoding());
331 return autoCommit;
334 void SAL_CALL OConnection::commit()
335 throw(SQLException, RuntimeException, std::exception)
337 OSL_TRACE("OConnection::commit");
338 MutexGuard aGuard(m_aMutex);
339 checkDisposed(OConnection_BASE::rBHelper.bDisposed);
340 try {
341 m_settings.cppConnection->commit();
342 } catch (const sql::SQLException & e) {
343 mysqlc_sdbc_driver::translateAndThrow(e, *this, getConnectionEncoding());
347 void SAL_CALL OConnection::rollback()
348 throw(SQLException, RuntimeException, std::exception)
350 OSL_TRACE("OConnection::rollback");
351 MutexGuard aGuard(m_aMutex);
352 checkDisposed(OConnection_BASE::rBHelper.bDisposed);
353 try {
354 m_settings.cppConnection->rollback();
355 } catch (const sql::SQLException & e) {
356 mysqlc_sdbc_driver::translateAndThrow(e, *this, getConnectionEncoding());
360 sal_Bool SAL_CALL OConnection::isClosed()
361 throw(SQLException, RuntimeException, std::exception)
363 OSL_TRACE("OConnection::isClosed");
364 MutexGuard aGuard(m_aMutex);
366 // just simple -> we are close when we are disposed that means someone called dispose(); (XComponent)
367 return OConnection_BASE::rBHelper.bDisposed;
370 Reference< XDatabaseMetaData > SAL_CALL OConnection::getMetaData()
371 throw(SQLException, RuntimeException, std::exception)
373 OSL_TRACE("OConnection::getMetaData");
374 MutexGuard aGuard(m_aMutex);
375 checkDisposed(OConnection_BASE::rBHelper.bDisposed);
377 Reference< XDatabaseMetaData > xMetaData = m_xMetaData;
378 if (!xMetaData.is()) {
379 try {
380 xMetaData = new ODatabaseMetaData(*this); // need the connection because it can return it
381 } catch (const sql::SQLException & e) {
382 mysqlc_sdbc_driver::translateAndThrow(e, *this, getConnectionEncoding());
384 m_xMetaData = xMetaData;
387 return xMetaData;
390 void SAL_CALL OConnection::setReadOnly(sal_Bool readOnly)
391 throw(SQLException, RuntimeException, std::exception)
393 OSL_TRACE("OConnection::setReadOnly");
394 MutexGuard aGuard(m_aMutex);
395 checkDisposed(OConnection_BASE::rBHelper.bDisposed);
397 m_settings.readOnly = readOnly;
400 sal_Bool SAL_CALL OConnection::isReadOnly()
401 throw(SQLException, RuntimeException, std::exception)
403 OSL_TRACE("OConnection::isReadOnly");
404 MutexGuard aGuard(m_aMutex);
405 checkDisposed(OConnection_BASE::rBHelper.bDisposed);
407 // return if your connection to readonly
408 return m_settings.readOnly;
411 void SAL_CALL OConnection::setCatalog(const rtl::OUString& catalog)
412 throw(SQLException, RuntimeException, std::exception)
414 OSL_TRACE("OConnection::setCatalog");
415 MutexGuard aGuard(m_aMutex);
416 checkDisposed(OConnection_BASE::rBHelper.bDisposed);
418 try {
419 // m_settings.cppConnection->setCatalog(rtl::OUStringToOString(catalog, m_settings.encoding).getStr());
420 m_settings.cppConnection->setSchema(rtl::OUStringToOString(catalog, getConnectionEncoding()).getStr());
421 } catch (sql::SQLException & e) {
422 mysqlc_sdbc_driver::translateAndThrow(e, *this, getConnectionEncoding());
426 rtl::OUString SAL_CALL OConnection::getCatalog()
427 throw(SQLException, RuntimeException, std::exception)
429 OSL_TRACE("OConnection::getCatalog");
430 MutexGuard aGuard(m_aMutex);
431 checkDisposed(OConnection_BASE::rBHelper.bDisposed);
433 rtl::OUString catalog;
434 try {
435 catalog = mysqlc_sdbc_driver::convert(m_settings.cppConnection->getSchema(), getConnectionEncoding());
436 } catch (const sql::SQLException & e) {
437 mysqlc_sdbc_driver::translateAndThrow(e, *this, getConnectionEncoding());
439 return catalog;
442 void SAL_CALL OConnection::setTransactionIsolation(sal_Int32 level)
443 throw(SQLException, RuntimeException, std::exception)
445 OSL_TRACE("OConnection::setTransactionIsolation");
446 MutexGuard aGuard(m_aMutex);
447 checkDisposed(OConnection_BASE::rBHelper.bDisposed);
449 sql::enum_transaction_isolation cpplevel = sql::TRANSACTION_SERIALIZABLE;
451 switch (level) {
452 case TransactionIsolation::READ_UNCOMMITTED:
453 cpplevel = sql::TRANSACTION_READ_UNCOMMITTED;
454 break;
455 case TransactionIsolation::READ_COMMITTED:
456 cpplevel = sql::TRANSACTION_READ_COMMITTED;
457 break;
458 case TransactionIsolation::REPEATABLE_READ:
459 cpplevel = sql::TRANSACTION_REPEATABLE_READ;
460 break;
461 case TransactionIsolation::SERIALIZABLE:
462 cpplevel = sql::TRANSACTION_SERIALIZABLE;
463 break;
464 case TransactionIsolation::NONE:
465 cpplevel = sql::TRANSACTION_SERIALIZABLE;
466 break;
467 default:;
468 /* XXX: Exception ?? */
470 try {
471 m_settings.cppConnection->setTransactionIsolation(cpplevel);
472 } catch (const sql::SQLException & e) {
473 mysqlc_sdbc_driver::translateAndThrow(e, *this, getConnectionEncoding());
477 sal_Int32 SAL_CALL OConnection::getTransactionIsolation()
478 throw(SQLException, RuntimeException, std::exception)
480 OSL_TRACE("OConnection::getTransactionIsolation");
481 MutexGuard aGuard(m_aMutex);
482 checkDisposed(OConnection_BASE::rBHelper.bDisposed);
484 try {
485 switch (m_settings.cppConnection->getTransactionIsolation()) {
486 case sql::TRANSACTION_SERIALIZABLE: return TransactionIsolation::SERIALIZABLE;
487 case sql::TRANSACTION_REPEATABLE_READ: return TransactionIsolation::REPEATABLE_READ;
488 case sql::TRANSACTION_READ_COMMITTED: return TransactionIsolation::READ_COMMITTED;
489 case sql::TRANSACTION_READ_UNCOMMITTED: return TransactionIsolation::READ_UNCOMMITTED;
490 default:
493 } catch (const sql::SQLException & e) {
494 mysqlc_sdbc_driver::translateAndThrow(e, *this, getConnectionEncoding());
496 return TransactionIsolation::NONE;
499 Reference<XNameAccess> SAL_CALL OConnection::getTypeMap()
500 throw(SQLException, RuntimeException, std::exception)
502 OSL_TRACE("OConnection::getTypeMap");
503 MutexGuard aGuard(m_aMutex);
504 checkDisposed(OConnection_BASE::rBHelper.bDisposed);
506 Reference<XNameAccess > t = m_typeMap;
507 return t;
510 void SAL_CALL OConnection::setTypeMap(const Reference<XNameAccess >& typeMap)
511 throw(SQLException, RuntimeException, std::exception)
513 OSL_TRACE("OConnection::setTypeMap");
514 MutexGuard aGuard(m_aMutex);
515 checkDisposed(OConnection_BASE::rBHelper.bDisposed);
517 m_typeMap = typeMap;
520 // XCloseable
521 void SAL_CALL OConnection::close()
522 throw(SQLException, RuntimeException, std::exception)
524 OSL_TRACE("OConnection::close");
526 we need block, because the mutex is a local variable,
527 which will guard the block
530 // we just dispose us
531 MutexGuard aGuard(m_aMutex);
532 checkDisposed(OConnection_BASE::rBHelper.bDisposed);
534 dispose();
537 // XWarningsSupplier
538 Any SAL_CALL OConnection::getWarnings()
539 throw(SQLException, RuntimeException, std::exception)
541 Any x = Any();
542 OSL_TRACE("OConnection::getWarnings");
543 // when you collected some warnings -> return it
544 return x;
547 void SAL_CALL OConnection::clearWarnings()
548 throw(SQLException, RuntimeException, std::exception)
550 OSL_TRACE("OConnection::clearWarnings");
551 // you should clear your collected warnings here#
554 void OConnection::disposing()
556 OSL_TRACE("OConnection::disposing");
557 // we noticed that we should be destroied in near future so we have to dispose our statements
558 MutexGuard aGuard(m_aMutex);
560 for (OWeakRefArray::iterator i = m_aStatements.begin(); i != m_aStatements.end() ; ++i) {
561 Reference< XComponent > xComp(i->get(), UNO_QUERY);
562 if (xComp.is()) {
563 xComp->dispose();
566 m_aStatements.clear();
568 m_bClosed = true;
569 m_xMetaData = WeakReference< XDatabaseMetaData >();
571 dispose_ChildImpl();
572 OConnection_BASE::disposing();
575 /* ToDo - upcast the connection to MySQL_Connection and use ::getSessionVariable() */
577 rtl::OUString OConnection::getMysqlVariable(const char *varname)
578 throw(SQLException, RuntimeException)
580 OSL_TRACE("OConnection::getMysqlVariable");
581 MutexGuard aGuard(m_aMutex);
582 checkDisposed(OConnection_BASE::rBHelper.bDisposed);
584 rtl::OUString ret;
585 rtl::OUStringBuffer aStatement;
586 aStatement.appendAscii( "SHOW SESSION VARIABLES LIKE '" );
587 aStatement.appendAscii( varname );
588 aStatement.append( '\'' );
590 try {
591 XStatement * stmt = new OStatement(this, m_settings.cppConnection->createStatement());
592 Reference< XResultSet > rs = stmt->executeQuery( aStatement.makeStringAndClear() );
593 if (rs.is() && rs->next()) {
594 Reference< XRow > xRow(rs, UNO_QUERY);
595 ret = xRow->getString(2);
597 } catch (const sql::SQLException & e) {
598 mysqlc_sdbc_driver::translateAndThrow(e, *this, getConnectionEncoding());
601 return ret;
604 sal_Int32 OConnection::getMysqlVersion()
605 throw(SQLException, RuntimeException)
607 OSL_TRACE("OConnection::getMysqlVersion");
608 MutexGuard aGuard(m_aMutex);
609 checkDisposed(OConnection_BASE::rBHelper.bDisposed);
611 sal_Int32 version(0);
612 try {
613 version = 10000 * m_settings.cppConnection->getMetaData()->getDatabaseMajorVersion();
614 version += 100 * m_settings.cppConnection->getMetaData()->getDatabaseMinorVersion();
615 version += m_settings.cppConnection->getMetaData()->getDatabasePatchVersion();
616 } catch (const sql::SQLException & e) {
617 mysqlc_sdbc_driver::translateAndThrow(e, *this, getConnectionEncoding());
619 return version;
622 // TODO: Not used
623 //sal_Int32 OConnection::sdbcColumnType(rtl::OUString typeName)
625 // OSL_TRACE("OConnection::sdbcColumnType");
626 // int i = 0;
627 // while (mysqlc_types[i].typeName) {
628 // if (rtl::OUString::createFromAscii(mysqlc_types[i].typeName).equals(
629 // typeName.toAsciiUpperCase()))
630 // {
631 // return mysqlc_types[i].dataType;
632 // }
633 // i++;
634 // }
635 // return 0;
638 rtl::OUString OConnection::transFormPreparedStatement(const rtl::OUString& _sSQL)
640 rtl::OUString sSqlStatement = _sSQL;
641 if ( !m_xParameterSubstitution.is() ) {
642 try {
643 Sequence< Any > aArgs(1);
644 Reference< XConnection> xCon = this;
645 aArgs[0] <<= NamedValue(rtl::OUString("ActiveConnection"), makeAny(xCon));
647 m_xParameterSubstitution.set(m_rDriver.getFactory()->createInstanceWithArguments(rtl::OUString("org.openoffice.comp.helper.ParameterSubstitution"),aArgs),UNO_QUERY);
648 } catch(const Exception&) {}
650 if ( m_xParameterSubstitution.is() ) {
651 try {
652 sSqlStatement = m_xParameterSubstitution->substituteVariables(sSqlStatement,sal_True);
653 } catch(const Exception&) { }
655 return sSqlStatement;
660 * Local variables:
661 * tab-width: 4
662 * c-basic-offset: 4
663 * End:
664 * vim600: noet sw=4 ts=4 fdm=marker
665 * vim<600: noet sw=4 ts=4
668 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */