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