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_preparedstatement.cxx,v $ 9*cdf0e10cSrcweir * 10*cdf0e10cSrcweir * $Revision: 1.1.2.5 $ 11*cdf0e10cSrcweir * 12*cdf0e10cSrcweir * This file is part of OpenOffice.org. 13*cdf0e10cSrcweir * 14*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 15*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 16*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 17*cdf0e10cSrcweir * 18*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 19*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 20*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 22*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 23*cdf0e10cSrcweir * 24*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 25*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 26*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 27*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 28*cdf0e10cSrcweir ************************************************************************/ 29*cdf0e10cSrcweir 30*cdf0e10cSrcweir #include "mysqlc_general.hxx" 31*cdf0e10cSrcweir #include "mysqlc_preparedstatement.hxx" 32*cdf0e10cSrcweir #include "mysqlc_propertyids.hxx" 33*cdf0e10cSrcweir #include "mysqlc_resultsetmetadata.hxx" 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp> 36*cdf0e10cSrcweir #include <com/sun/star/sdbc/DataType.hpp> 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir #include <cppconn/connection.h> 39*cdf0e10cSrcweir #include <cppconn/exception.h> 40*cdf0e10cSrcweir #include <cppconn/parameter_metadata.h> 41*cdf0e10cSrcweir #include <cppconn/prepared_statement.h> 42*cdf0e10cSrcweir #include <cppconn/statement.h> 43*cdf0e10cSrcweir #include <cppuhelper/typeprovider.hxx> 44*cdf0e10cSrcweir #include <osl/diagnose.h> 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir #include <stdio.h> 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir using namespace connectivity::mysqlc; 49*cdf0e10cSrcweir using namespace com::sun::star::uno; 50*cdf0e10cSrcweir using namespace com::sun::star::lang; 51*cdf0e10cSrcweir using namespace com::sun::star::beans; 52*cdf0e10cSrcweir using namespace com::sun::star::sdbc; 53*cdf0e10cSrcweir using namespace com::sun::star::container; 54*cdf0e10cSrcweir using namespace com::sun::star::io; 55*cdf0e10cSrcweir using namespace com::sun::star::util; 56*cdf0e10cSrcweir using ::osl::MutexGuard; 57*cdf0e10cSrcweir using mysqlc_sdbc_driver::getStringFromAny; 58*cdf0e10cSrcweir 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir /* {{{ my_i_to_a() -I- */ 61*cdf0e10cSrcweir static inline char * my_i_to_a(char * buf, size_t buf_size, int a) 62*cdf0e10cSrcweir { 63*cdf0e10cSrcweir snprintf(buf, buf_size, "%d", a); 64*cdf0e10cSrcweir return buf; 65*cdf0e10cSrcweir } 66*cdf0e10cSrcweir /* }}} */ 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir IMPLEMENT_SERVICE_INFO(OPreparedStatement,"com.sun.star.sdbcx.mysqlc.PreparedStatement","com.sun.star.sdbc.PreparedStatement"); 70*cdf0e10cSrcweir 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir /* {{{ OPreparedStatement::OPreparedStatement() -I- */ 73*cdf0e10cSrcweir OPreparedStatement::OPreparedStatement(OConnection* _pConnection, sql::PreparedStatement * _cppPrepStmt) 74*cdf0e10cSrcweir :OCommonStatement(_pConnection, _cppPrepStmt) 75*cdf0e10cSrcweir { 76*cdf0e10cSrcweir OSL_TRACE("OPreparedStatement::OPreparedStatement"); 77*cdf0e10cSrcweir m_pConnection = _pConnection; 78*cdf0e10cSrcweir m_pConnection->acquire(); 79*cdf0e10cSrcweir 80*cdf0e10cSrcweir try { 81*cdf0e10cSrcweir m_paramCount = ((sql::PreparedStatement *)cppStatement)->getParameterMetaData()->getParameterCount(); 82*cdf0e10cSrcweir } catch (sql::SQLException &e) { 83*cdf0e10cSrcweir mysqlc_sdbc_driver::translateAndThrow(e, *this, m_pConnection->getConnectionEncoding()); 84*cdf0e10cSrcweir } 85*cdf0e10cSrcweir } 86*cdf0e10cSrcweir /* }}} */ 87*cdf0e10cSrcweir 88*cdf0e10cSrcweir 89*cdf0e10cSrcweir /* {{{ OPreparedStatement::~OPreparedStatement() -I- */ 90*cdf0e10cSrcweir OPreparedStatement::~OPreparedStatement() 91*cdf0e10cSrcweir { 92*cdf0e10cSrcweir OSL_TRACE("OPreparedStatement::~OPreparedStatement"); 93*cdf0e10cSrcweir } 94*cdf0e10cSrcweir /* }}} */ 95*cdf0e10cSrcweir 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir /* {{{ OPreparedStatement::acquire() -I- */ 98*cdf0e10cSrcweir void SAL_CALL OPreparedStatement::acquire() 99*cdf0e10cSrcweir throw() 100*cdf0e10cSrcweir { 101*cdf0e10cSrcweir OSL_TRACE("OPreparedStatement::acquire"); 102*cdf0e10cSrcweir OCommonStatement::acquire(); 103*cdf0e10cSrcweir } 104*cdf0e10cSrcweir /* }}} */ 105*cdf0e10cSrcweir 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir /* {{{ OPreparedStatement::release() -I- */ 108*cdf0e10cSrcweir void SAL_CALL OPreparedStatement::release() 109*cdf0e10cSrcweir throw() 110*cdf0e10cSrcweir { 111*cdf0e10cSrcweir OSL_TRACE("OPreparedStatement::release"); 112*cdf0e10cSrcweir OCommonStatement::release(); 113*cdf0e10cSrcweir } 114*cdf0e10cSrcweir /* }}} */ 115*cdf0e10cSrcweir 116*cdf0e10cSrcweir 117*cdf0e10cSrcweir /* {{{ OPreparedStatement::queryInterface() -I- */ 118*cdf0e10cSrcweir Any SAL_CALL OPreparedStatement::queryInterface(const Type & rType) 119*cdf0e10cSrcweir throw(RuntimeException) 120*cdf0e10cSrcweir { 121*cdf0e10cSrcweir OSL_TRACE("OPreparedStatement::queryInterface"); 122*cdf0e10cSrcweir Any aRet = OCommonStatement::queryInterface(rType); 123*cdf0e10cSrcweir if (!aRet.hasValue()) { 124*cdf0e10cSrcweir aRet = OPreparedStatement_BASE::queryInterface(rType); 125*cdf0e10cSrcweir } 126*cdf0e10cSrcweir return (aRet); 127*cdf0e10cSrcweir } 128*cdf0e10cSrcweir /* }}} */ 129*cdf0e10cSrcweir 130*cdf0e10cSrcweir 131*cdf0e10cSrcweir /* {{{ OPreparedStatement::getPropertySetInfo() -I- */ 132*cdf0e10cSrcweir Sequence< Type > SAL_CALL OPreparedStatement::getTypes() 133*cdf0e10cSrcweir throw(RuntimeException) 134*cdf0e10cSrcweir { 135*cdf0e10cSrcweir OSL_TRACE("OPreparedStatement::getTypes"); 136*cdf0e10cSrcweir return concatSequences(OPreparedStatement_BASE::getTypes(), OCommonStatement::getTypes()); 137*cdf0e10cSrcweir } 138*cdf0e10cSrcweir /* }}} */ 139*cdf0e10cSrcweir 140*cdf0e10cSrcweir 141*cdf0e10cSrcweir /* {{{ OPreparedStatement::getMetaData() -I- */ 142*cdf0e10cSrcweir Reference< XResultSetMetaData > SAL_CALL OPreparedStatement::getMetaData() 143*cdf0e10cSrcweir throw(SQLException, RuntimeException) 144*cdf0e10cSrcweir { 145*cdf0e10cSrcweir OSL_TRACE("OPreparedStatement::getMetaData"); 146*cdf0e10cSrcweir MutexGuard aGuard(m_aMutex); 147*cdf0e10cSrcweir checkDisposed(OPreparedStatement::rBHelper.bDisposed); 148*cdf0e10cSrcweir 149*cdf0e10cSrcweir try { 150*cdf0e10cSrcweir if (!m_xMetaData.is()) { 151*cdf0e10cSrcweir m_xMetaData = new OResultSetMetaData( 152*cdf0e10cSrcweir ((sql::PreparedStatement *)cppStatement)->getMetaData(), 153*cdf0e10cSrcweir getOwnConnection()->getConnectionEncoding() 154*cdf0e10cSrcweir ); 155*cdf0e10cSrcweir } 156*cdf0e10cSrcweir } catch (sql::MethodNotImplementedException) { 157*cdf0e10cSrcweir mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::getMetaData", *this); 158*cdf0e10cSrcweir } catch (sql::SQLException &e) { 159*cdf0e10cSrcweir mysqlc_sdbc_driver::translateAndThrow(e, *this, m_pConnection->getConnectionEncoding()); 160*cdf0e10cSrcweir } 161*cdf0e10cSrcweir return m_xMetaData; 162*cdf0e10cSrcweir } 163*cdf0e10cSrcweir /* }}} */ 164*cdf0e10cSrcweir 165*cdf0e10cSrcweir 166*cdf0e10cSrcweir /* {{{ OPreparedStatement::close() -I- */ 167*cdf0e10cSrcweir void SAL_CALL OPreparedStatement::close() 168*cdf0e10cSrcweir throw(SQLException, RuntimeException) 169*cdf0e10cSrcweir { 170*cdf0e10cSrcweir OSL_TRACE("OPreparedStatement::close"); 171*cdf0e10cSrcweir 172*cdf0e10cSrcweir MutexGuard aGuard(m_aMutex); 173*cdf0e10cSrcweir checkDisposed(OPreparedStatement::rBHelper.bDisposed); 174*cdf0e10cSrcweir 175*cdf0e10cSrcweir try { 176*cdf0e10cSrcweir clearWarnings(); 177*cdf0e10cSrcweir clearParameters(); 178*cdf0e10cSrcweir OCommonStatement::close(); 179*cdf0e10cSrcweir } catch (SQLException) { 180*cdf0e10cSrcweir // If we get an error, ignore 181*cdf0e10cSrcweir } 182*cdf0e10cSrcweir 183*cdf0e10cSrcweir // Remove this Statement object from the Connection object's 184*cdf0e10cSrcweir // list 185*cdf0e10cSrcweir } 186*cdf0e10cSrcweir /* }}} */ 187*cdf0e10cSrcweir 188*cdf0e10cSrcweir 189*cdf0e10cSrcweir /* {{{ OPreparedStatement::execute() -I- */ 190*cdf0e10cSrcweir sal_Bool SAL_CALL OPreparedStatement::execute() 191*cdf0e10cSrcweir throw(SQLException, RuntimeException) 192*cdf0e10cSrcweir { 193*cdf0e10cSrcweir OSL_TRACE("OPreparedStatement::execute"); 194*cdf0e10cSrcweir MutexGuard aGuard(m_aMutex); 195*cdf0e10cSrcweir checkDisposed(OPreparedStatement::rBHelper.bDisposed); 196*cdf0e10cSrcweir 197*cdf0e10cSrcweir sal_Bool success = sal_False; 198*cdf0e10cSrcweir try { 199*cdf0e10cSrcweir success = ((sql::PreparedStatement *)cppStatement)->execute()? sal_True:sal_False; 200*cdf0e10cSrcweir } catch (sql::SQLException &e) { 201*cdf0e10cSrcweir mysqlc_sdbc_driver::translateAndThrow(e, *this, m_pConnection->getConnectionEncoding()); 202*cdf0e10cSrcweir } 203*cdf0e10cSrcweir return success; 204*cdf0e10cSrcweir } 205*cdf0e10cSrcweir /* }}} */ 206*cdf0e10cSrcweir 207*cdf0e10cSrcweir 208*cdf0e10cSrcweir /* {{{ OPreparedStatement::executeUpdate() -I- */ 209*cdf0e10cSrcweir sal_Int32 SAL_CALL OPreparedStatement::executeUpdate() 210*cdf0e10cSrcweir throw(SQLException, RuntimeException) 211*cdf0e10cSrcweir { 212*cdf0e10cSrcweir OSL_TRACE("OPreparedStatement::executeUpdate"); 213*cdf0e10cSrcweir MutexGuard aGuard(m_aMutex); 214*cdf0e10cSrcweir checkDisposed(OPreparedStatement::rBHelper.bDisposed); 215*cdf0e10cSrcweir 216*cdf0e10cSrcweir sal_Int32 affectedRows = sal_False; 217*cdf0e10cSrcweir try { 218*cdf0e10cSrcweir affectedRows = ((sql::PreparedStatement *)cppStatement)->executeUpdate(); 219*cdf0e10cSrcweir } catch (sql::SQLException &e) { 220*cdf0e10cSrcweir mysqlc_sdbc_driver::translateAndThrow(e, *this, m_pConnection->getConnectionEncoding()); 221*cdf0e10cSrcweir } 222*cdf0e10cSrcweir return affectedRows; 223*cdf0e10cSrcweir } 224*cdf0e10cSrcweir /* }}} */ 225*cdf0e10cSrcweir 226*cdf0e10cSrcweir 227*cdf0e10cSrcweir /* {{{ OPreparedStatement::getPropertySetInfo() -I- */ 228*cdf0e10cSrcweir void SAL_CALL OPreparedStatement::setString(sal_Int32 parameter, const OUString& x) 229*cdf0e10cSrcweir throw(SQLException, RuntimeException) 230*cdf0e10cSrcweir { 231*cdf0e10cSrcweir OSL_TRACE("OPreparedStatement::setString"); 232*cdf0e10cSrcweir MutexGuard aGuard(m_aMutex); 233*cdf0e10cSrcweir checkDisposed(OPreparedStatement::rBHelper.bDisposed); 234*cdf0e10cSrcweir checkParameterIndex(parameter); 235*cdf0e10cSrcweir 236*cdf0e10cSrcweir try { 237*cdf0e10cSrcweir ext_std::string stringie(::rtl::OUStringToOString(x, m_pConnection->getConnectionEncoding()).getStr()); 238*cdf0e10cSrcweir ((sql::PreparedStatement *)cppStatement)->setString(parameter, stringie); 239*cdf0e10cSrcweir } catch (sql::MethodNotImplementedException) { 240*cdf0e10cSrcweir mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::clearParameters", *this); 241*cdf0e10cSrcweir } catch (sql::SQLException &e) { 242*cdf0e10cSrcweir mysqlc_sdbc_driver::translateAndThrow(e, *this, m_pConnection->getConnectionEncoding()); 243*cdf0e10cSrcweir } 244*cdf0e10cSrcweir } 245*cdf0e10cSrcweir /* }}} */ 246*cdf0e10cSrcweir 247*cdf0e10cSrcweir 248*cdf0e10cSrcweir /* {{{ OPreparedStatement::getConnection() -I- */ 249*cdf0e10cSrcweir Reference< XConnection > SAL_CALL OPreparedStatement::getConnection() 250*cdf0e10cSrcweir throw(SQLException, RuntimeException) 251*cdf0e10cSrcweir { 252*cdf0e10cSrcweir OSL_TRACE("OPreparedStatement::getConnection"); 253*cdf0e10cSrcweir MutexGuard aGuard(m_aMutex); 254*cdf0e10cSrcweir checkDisposed(OPreparedStatement::rBHelper.bDisposed); 255*cdf0e10cSrcweir 256*cdf0e10cSrcweir return (Reference< XConnection >)m_pConnection; 257*cdf0e10cSrcweir } 258*cdf0e10cSrcweir /* }}} */ 259*cdf0e10cSrcweir 260*cdf0e10cSrcweir Reference< XResultSet > SAL_CALL OPreparedStatement::executeQuery(const OUString& sql) 261*cdf0e10cSrcweir throw(SQLException, RuntimeException) 262*cdf0e10cSrcweir { 263*cdf0e10cSrcweir return OCommonStatement::executeQuery( sql ); 264*cdf0e10cSrcweir } 265*cdf0e10cSrcweir 266*cdf0e10cSrcweir sal_Int32 SAL_CALL OPreparedStatement::executeUpdate(const OUString& sql) 267*cdf0e10cSrcweir throw(SQLException, RuntimeException) 268*cdf0e10cSrcweir { 269*cdf0e10cSrcweir return OCommonStatement::executeUpdate( sql ); 270*cdf0e10cSrcweir } 271*cdf0e10cSrcweir 272*cdf0e10cSrcweir sal_Bool SAL_CALL OPreparedStatement::execute( const OUString& sql ) 273*cdf0e10cSrcweir throw(SQLException, RuntimeException) 274*cdf0e10cSrcweir { 275*cdf0e10cSrcweir return OCommonStatement::execute( sql ); 276*cdf0e10cSrcweir } 277*cdf0e10cSrcweir 278*cdf0e10cSrcweir /* {{{ OPreparedStatement::executeQuery() -I- */ 279*cdf0e10cSrcweir Reference< XResultSet > SAL_CALL OPreparedStatement::executeQuery() 280*cdf0e10cSrcweir throw(SQLException, RuntimeException) 281*cdf0e10cSrcweir { 282*cdf0e10cSrcweir OSL_TRACE("OPreparedStatement::executeQuery"); 283*cdf0e10cSrcweir MutexGuard aGuard(m_aMutex); 284*cdf0e10cSrcweir checkDisposed(OPreparedStatement::rBHelper.bDisposed); 285*cdf0e10cSrcweir 286*cdf0e10cSrcweir Reference< XResultSet > xResultSet; 287*cdf0e10cSrcweir try { 288*cdf0e10cSrcweir sql::ResultSet * res = ((sql::PreparedStatement *)cppStatement)->executeQuery(); 289*cdf0e10cSrcweir xResultSet = new OResultSet(this, res, getOwnConnection()->getConnectionEncoding()); 290*cdf0e10cSrcweir } catch (sql::SQLException &e) { 291*cdf0e10cSrcweir mysqlc_sdbc_driver::translateAndThrow(e, *this, m_pConnection->getConnectionEncoding()); 292*cdf0e10cSrcweir } 293*cdf0e10cSrcweir return xResultSet; 294*cdf0e10cSrcweir } 295*cdf0e10cSrcweir /* }}} */ 296*cdf0e10cSrcweir 297*cdf0e10cSrcweir 298*cdf0e10cSrcweir /* {{{ OPreparedStatement::setBoolean() -I- */ 299*cdf0e10cSrcweir void SAL_CALL OPreparedStatement::setBoolean(sal_Int32 parameter, sal_Bool x) 300*cdf0e10cSrcweir throw(SQLException, RuntimeException) 301*cdf0e10cSrcweir { 302*cdf0e10cSrcweir OSL_TRACE("OPreparedStatement::setBoolean"); 303*cdf0e10cSrcweir MutexGuard aGuard(m_aMutex); 304*cdf0e10cSrcweir checkDisposed(OPreparedStatement::rBHelper.bDisposed); 305*cdf0e10cSrcweir checkParameterIndex(parameter); 306*cdf0e10cSrcweir 307*cdf0e10cSrcweir try { 308*cdf0e10cSrcweir ((sql::PreparedStatement *)cppStatement)->setBoolean(parameter, x); 309*cdf0e10cSrcweir } catch (sql::MethodNotImplementedException) { 310*cdf0e10cSrcweir mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setBoolean", *this); 311*cdf0e10cSrcweir } catch (sql::SQLException &e) { 312*cdf0e10cSrcweir mysqlc_sdbc_driver::translateAndThrow(e, *this, m_pConnection->getConnectionEncoding()); 313*cdf0e10cSrcweir } 314*cdf0e10cSrcweir } 315*cdf0e10cSrcweir /* }}} */ 316*cdf0e10cSrcweir 317*cdf0e10cSrcweir 318*cdf0e10cSrcweir /* {{{ OPreparedStatement::setByte() -I- */ 319*cdf0e10cSrcweir void SAL_CALL OPreparedStatement::setByte(sal_Int32 parameter, sal_Int8 x) 320*cdf0e10cSrcweir throw(SQLException, RuntimeException) 321*cdf0e10cSrcweir { 322*cdf0e10cSrcweir OSL_TRACE("OPreparedStatement::setByte"); 323*cdf0e10cSrcweir MutexGuard aGuard(m_aMutex); 324*cdf0e10cSrcweir checkDisposed(OPreparedStatement::rBHelper.bDisposed); 325*cdf0e10cSrcweir checkParameterIndex(parameter); 326*cdf0e10cSrcweir 327*cdf0e10cSrcweir try { 328*cdf0e10cSrcweir ((sql::PreparedStatement *)cppStatement)->setInt(parameter, x); 329*cdf0e10cSrcweir } catch (sql::MethodNotImplementedException) { 330*cdf0e10cSrcweir mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setByte", *this); 331*cdf0e10cSrcweir } catch (sql::SQLException &e) { 332*cdf0e10cSrcweir mysqlc_sdbc_driver::translateAndThrow(e, *this, m_pConnection->getConnectionEncoding()); 333*cdf0e10cSrcweir } 334*cdf0e10cSrcweir } 335*cdf0e10cSrcweir /* }}} */ 336*cdf0e10cSrcweir 337*cdf0e10cSrcweir 338*cdf0e10cSrcweir /* {{{ OPreparedStatement::setDate() -I- */ 339*cdf0e10cSrcweir void SAL_CALL OPreparedStatement::setDate(sal_Int32 parameter, const Date& aData) 340*cdf0e10cSrcweir throw(SQLException, RuntimeException) 341*cdf0e10cSrcweir { 342*cdf0e10cSrcweir OSL_TRACE("OPreparedStatement::setDate"); 343*cdf0e10cSrcweir MutexGuard aGuard(m_aMutex); 344*cdf0e10cSrcweir checkDisposed(OPreparedStatement::rBHelper.bDisposed); 345*cdf0e10cSrcweir checkParameterIndex(parameter); 346*cdf0e10cSrcweir 347*cdf0e10cSrcweir ext_std::string dateStr; 348*cdf0e10cSrcweir char buf[20]; 349*cdf0e10cSrcweir dateStr.append(my_i_to_a(buf, sizeof(buf)-1, aData.Year)); 350*cdf0e10cSrcweir dateStr.append("-", 1); 351*cdf0e10cSrcweir dateStr.append(my_i_to_a(buf, sizeof(buf)-1, aData.Month)); 352*cdf0e10cSrcweir dateStr.append("-", 1); 353*cdf0e10cSrcweir dateStr.append(my_i_to_a(buf, sizeof(buf)-1, aData.Day)); 354*cdf0e10cSrcweir 355*cdf0e10cSrcweir try { 356*cdf0e10cSrcweir ((sql::PreparedStatement *)cppStatement)->setDateTime(parameter, dateStr); 357*cdf0e10cSrcweir } catch (sql::MethodNotImplementedException) { 358*cdf0e10cSrcweir mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setDate", *this); 359*cdf0e10cSrcweir } catch (sql::SQLException &e) { 360*cdf0e10cSrcweir mysqlc_sdbc_driver::translateAndThrow(e, *this, m_pConnection->getConnectionEncoding()); 361*cdf0e10cSrcweir } 362*cdf0e10cSrcweir } 363*cdf0e10cSrcweir /* }}} */ 364*cdf0e10cSrcweir 365*cdf0e10cSrcweir 366*cdf0e10cSrcweir /* {{{ OPreparedStatement::setTime() -I- */ 367*cdf0e10cSrcweir void SAL_CALL OPreparedStatement::setTime(sal_Int32 parameter, const Time& aVal) 368*cdf0e10cSrcweir throw(SQLException, RuntimeException) 369*cdf0e10cSrcweir { 370*cdf0e10cSrcweir OSL_TRACE("OPreparedStatement::setTime"); 371*cdf0e10cSrcweir MutexGuard aGuard(m_aMutex); 372*cdf0e10cSrcweir checkDisposed(OPreparedStatement::rBHelper.bDisposed); 373*cdf0e10cSrcweir checkParameterIndex(parameter); 374*cdf0e10cSrcweir 375*cdf0e10cSrcweir ext_std::string timeStr; 376*cdf0e10cSrcweir char buf[20]; 377*cdf0e10cSrcweir timeStr.append(my_i_to_a(buf, sizeof(buf)-1, aVal.Hours)); 378*cdf0e10cSrcweir timeStr.append(":", 1); 379*cdf0e10cSrcweir timeStr.append(my_i_to_a(buf, sizeof(buf)-1, aVal.Minutes)); 380*cdf0e10cSrcweir timeStr.append(":", 1); 381*cdf0e10cSrcweir timeStr.append(my_i_to_a(buf, sizeof(buf)-1, aVal.Seconds)); 382*cdf0e10cSrcweir 383*cdf0e10cSrcweir try { 384*cdf0e10cSrcweir ((sql::PreparedStatement *)cppStatement)->setDateTime(parameter, timeStr); 385*cdf0e10cSrcweir } catch (sql::MethodNotImplementedException) { 386*cdf0e10cSrcweir mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setTime", *this); 387*cdf0e10cSrcweir } catch (sql::SQLException &e) { 388*cdf0e10cSrcweir mysqlc_sdbc_driver::translateAndThrow(e, *this, m_pConnection->getConnectionEncoding()); 389*cdf0e10cSrcweir } 390*cdf0e10cSrcweir } 391*cdf0e10cSrcweir /* }}} */ 392*cdf0e10cSrcweir 393*cdf0e10cSrcweir 394*cdf0e10cSrcweir /* {{{ OPreparedStatement::setTimestamp() -I- */ 395*cdf0e10cSrcweir void SAL_CALL OPreparedStatement::setTimestamp(sal_Int32 parameter, const DateTime& aVal) 396*cdf0e10cSrcweir throw(SQLException, RuntimeException) 397*cdf0e10cSrcweir { 398*cdf0e10cSrcweir OSL_TRACE("OPreparedStatement::setTimestamp"); 399*cdf0e10cSrcweir MutexGuard aGuard(m_aMutex); 400*cdf0e10cSrcweir checkDisposed(OPreparedStatement::rBHelper.bDisposed); 401*cdf0e10cSrcweir checkParameterIndex(parameter); 402*cdf0e10cSrcweir 403*cdf0e10cSrcweir ext_std::string timeStr; 404*cdf0e10cSrcweir char buf[20]; 405*cdf0e10cSrcweir timeStr.append(my_i_to_a(buf, sizeof(buf)-1, aVal.Year)); 406*cdf0e10cSrcweir timeStr.append("-", 1); 407*cdf0e10cSrcweir timeStr.append(my_i_to_a(buf, sizeof(buf)-1, aVal.Month)); 408*cdf0e10cSrcweir timeStr.append("-", 1); 409*cdf0e10cSrcweir timeStr.append(my_i_to_a(buf, sizeof(buf)-1, aVal.Day)); 410*cdf0e10cSrcweir 411*cdf0e10cSrcweir timeStr.append(" ", 1); 412*cdf0e10cSrcweir 413*cdf0e10cSrcweir timeStr.append(my_i_to_a(buf, sizeof(buf)-1, aVal.Hours)); 414*cdf0e10cSrcweir timeStr.append(":", 1); 415*cdf0e10cSrcweir timeStr.append(my_i_to_a(buf, sizeof(buf)-1, aVal.Minutes)); 416*cdf0e10cSrcweir timeStr.append(":", 1); 417*cdf0e10cSrcweir timeStr.append(my_i_to_a(buf, sizeof(buf)-1, aVal.Seconds)); 418*cdf0e10cSrcweir 419*cdf0e10cSrcweir try { 420*cdf0e10cSrcweir ((sql::PreparedStatement *)cppStatement)->setDateTime(parameter, timeStr); 421*cdf0e10cSrcweir } catch (sql::MethodNotImplementedException) { 422*cdf0e10cSrcweir mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setTimestamp", *this); 423*cdf0e10cSrcweir } catch (sql::SQLException &e) { 424*cdf0e10cSrcweir mysqlc_sdbc_driver::translateAndThrow(e, *this, m_pConnection->getConnectionEncoding()); 425*cdf0e10cSrcweir } 426*cdf0e10cSrcweir } 427*cdf0e10cSrcweir /* }}} */ 428*cdf0e10cSrcweir 429*cdf0e10cSrcweir 430*cdf0e10cSrcweir /* {{{ OPreparedStatement::setDouble() -I- */ 431*cdf0e10cSrcweir void SAL_CALL OPreparedStatement::setDouble(sal_Int32 parameter, double x) 432*cdf0e10cSrcweir throw(SQLException, RuntimeException) 433*cdf0e10cSrcweir { 434*cdf0e10cSrcweir OSL_TRACE("OPreparedStatement::setDouble"); 435*cdf0e10cSrcweir MutexGuard aGuard(m_aMutex); 436*cdf0e10cSrcweir checkDisposed(OPreparedStatement::rBHelper.bDisposed); 437*cdf0e10cSrcweir checkParameterIndex(parameter); 438*cdf0e10cSrcweir 439*cdf0e10cSrcweir try { 440*cdf0e10cSrcweir ((sql::PreparedStatement *)cppStatement)->setDouble(parameter, x); 441*cdf0e10cSrcweir } catch (sql::MethodNotImplementedException) { 442*cdf0e10cSrcweir mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setDouble", *this); 443*cdf0e10cSrcweir } catch (sql::SQLException &e) { 444*cdf0e10cSrcweir mysqlc_sdbc_driver::translateAndThrow(e, *this, m_pConnection->getConnectionEncoding()); 445*cdf0e10cSrcweir } 446*cdf0e10cSrcweir } 447*cdf0e10cSrcweir /* }}} */ 448*cdf0e10cSrcweir 449*cdf0e10cSrcweir 450*cdf0e10cSrcweir /* {{{ OPreparedStatement::setFloat() -I- */ 451*cdf0e10cSrcweir void SAL_CALL OPreparedStatement::setFloat(sal_Int32 parameter, float x) 452*cdf0e10cSrcweir throw(SQLException, RuntimeException) 453*cdf0e10cSrcweir { 454*cdf0e10cSrcweir OSL_TRACE("OPreparedStatement::setFloat"); 455*cdf0e10cSrcweir MutexGuard aGuard(m_aMutex); 456*cdf0e10cSrcweir checkDisposed(OPreparedStatement::rBHelper.bDisposed); 457*cdf0e10cSrcweir checkParameterIndex(parameter); 458*cdf0e10cSrcweir 459*cdf0e10cSrcweir try { 460*cdf0e10cSrcweir ((sql::PreparedStatement *)cppStatement)->setDouble(parameter, x); 461*cdf0e10cSrcweir } catch (sql::MethodNotImplementedException) { 462*cdf0e10cSrcweir mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setFloat", *this); 463*cdf0e10cSrcweir } catch (sql::SQLException &e) { 464*cdf0e10cSrcweir mysqlc_sdbc_driver::translateAndThrow(e, *this, m_pConnection->getConnectionEncoding()); 465*cdf0e10cSrcweir } 466*cdf0e10cSrcweir } 467*cdf0e10cSrcweir /* }}} */ 468*cdf0e10cSrcweir 469*cdf0e10cSrcweir 470*cdf0e10cSrcweir /* {{{ OPreparedStatement::setInt() -I- */ 471*cdf0e10cSrcweir void SAL_CALL OPreparedStatement::setInt(sal_Int32 parameter, sal_Int32 x) 472*cdf0e10cSrcweir throw(SQLException, RuntimeException) 473*cdf0e10cSrcweir { 474*cdf0e10cSrcweir OSL_TRACE("OPreparedStatement::setInt"); 475*cdf0e10cSrcweir MutexGuard aGuard(m_aMutex); 476*cdf0e10cSrcweir checkDisposed(OPreparedStatement::rBHelper.bDisposed); 477*cdf0e10cSrcweir checkParameterIndex(parameter); 478*cdf0e10cSrcweir 479*cdf0e10cSrcweir try { 480*cdf0e10cSrcweir ((sql::PreparedStatement *)cppStatement)->setInt(parameter, x); 481*cdf0e10cSrcweir } catch (sql::MethodNotImplementedException) { 482*cdf0e10cSrcweir mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setInt", *this); 483*cdf0e10cSrcweir } catch (sql::SQLException &e) { 484*cdf0e10cSrcweir mysqlc_sdbc_driver::translateAndThrow(e, *this, m_pConnection->getConnectionEncoding()); 485*cdf0e10cSrcweir } 486*cdf0e10cSrcweir } 487*cdf0e10cSrcweir /* }}} */ 488*cdf0e10cSrcweir 489*cdf0e10cSrcweir 490*cdf0e10cSrcweir /* {{{ OPreparedStatement::setLong() -I- */ 491*cdf0e10cSrcweir void SAL_CALL OPreparedStatement::setLong(sal_Int32 parameter, sal_Int64 aVal) 492*cdf0e10cSrcweir throw(SQLException, RuntimeException) 493*cdf0e10cSrcweir { 494*cdf0e10cSrcweir OSL_TRACE("OPreparedStatement::setLong"); 495*cdf0e10cSrcweir MutexGuard aGuard(m_aMutex); 496*cdf0e10cSrcweir checkDisposed(OPreparedStatement::rBHelper.bDisposed); 497*cdf0e10cSrcweir checkParameterIndex(parameter); 498*cdf0e10cSrcweir 499*cdf0e10cSrcweir try { 500*cdf0e10cSrcweir ((sql::PreparedStatement *)cppStatement)->setInt64(parameter, aVal); 501*cdf0e10cSrcweir } catch (sql::MethodNotImplementedException) { 502*cdf0e10cSrcweir mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setLong", *this); 503*cdf0e10cSrcweir } catch (sql::SQLException &e) { 504*cdf0e10cSrcweir mysqlc_sdbc_driver::translateAndThrow(e, *this, m_pConnection->getConnectionEncoding()); 505*cdf0e10cSrcweir } 506*cdf0e10cSrcweir } 507*cdf0e10cSrcweir /* }}} */ 508*cdf0e10cSrcweir 509*cdf0e10cSrcweir 510*cdf0e10cSrcweir /* {{{ OPreparedStatement::setNull() -I- */ 511*cdf0e10cSrcweir void SAL_CALL OPreparedStatement::setNull(sal_Int32 parameter, sal_Int32 sqlType) 512*cdf0e10cSrcweir throw(SQLException, RuntimeException) 513*cdf0e10cSrcweir { 514*cdf0e10cSrcweir OSL_TRACE("OPreparedStatement::setNull"); 515*cdf0e10cSrcweir MutexGuard aGuard(m_aMutex); 516*cdf0e10cSrcweir checkDisposed(OPreparedStatement::rBHelper.bDisposed); 517*cdf0e10cSrcweir checkParameterIndex(parameter); 518*cdf0e10cSrcweir 519*cdf0e10cSrcweir try { 520*cdf0e10cSrcweir ((sql::PreparedStatement *)cppStatement)->setNull(parameter, sqlType); 521*cdf0e10cSrcweir } catch (sql::MethodNotImplementedException) { 522*cdf0e10cSrcweir mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setNull", *this); 523*cdf0e10cSrcweir } catch (sql::SQLException &e) { 524*cdf0e10cSrcweir mysqlc_sdbc_driver::translateAndThrow(e, *this, m_pConnection->getConnectionEncoding()); 525*cdf0e10cSrcweir } 526*cdf0e10cSrcweir } 527*cdf0e10cSrcweir /* }}} */ 528*cdf0e10cSrcweir 529*cdf0e10cSrcweir 530*cdf0e10cSrcweir /* {{{ OPreparedStatement::setClob() -U- */ 531*cdf0e10cSrcweir void SAL_CALL OPreparedStatement::setClob(sal_Int32 parameter, const Reference< XClob >& /* x */) 532*cdf0e10cSrcweir throw(SQLException, RuntimeException) 533*cdf0e10cSrcweir { 534*cdf0e10cSrcweir OSL_TRACE("OPreparedStatement::setClob"); 535*cdf0e10cSrcweir MutexGuard aGuard(m_aMutex); 536*cdf0e10cSrcweir checkDisposed(OPreparedStatement::rBHelper.bDisposed); 537*cdf0e10cSrcweir checkParameterIndex(parameter); 538*cdf0e10cSrcweir 539*cdf0e10cSrcweir mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setClob", *this); 540*cdf0e10cSrcweir } 541*cdf0e10cSrcweir /* }}} */ 542*cdf0e10cSrcweir 543*cdf0e10cSrcweir 544*cdf0e10cSrcweir /* {{{ OPreparedStatement::setBlob() -U- */ 545*cdf0e10cSrcweir void SAL_CALL OPreparedStatement::setBlob(sal_Int32 parameter, const Reference< XBlob >& /* x */) 546*cdf0e10cSrcweir throw(SQLException, RuntimeException) 547*cdf0e10cSrcweir { 548*cdf0e10cSrcweir OSL_TRACE("OPreparedStatement::setBlob"); 549*cdf0e10cSrcweir MutexGuard aGuard(m_aMutex); 550*cdf0e10cSrcweir checkDisposed(OPreparedStatement::rBHelper.bDisposed); 551*cdf0e10cSrcweir checkParameterIndex(parameter); 552*cdf0e10cSrcweir 553*cdf0e10cSrcweir mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setBlob", *this); 554*cdf0e10cSrcweir } 555*cdf0e10cSrcweir /* }}} */ 556*cdf0e10cSrcweir 557*cdf0e10cSrcweir 558*cdf0e10cSrcweir /* {{{ OPreparedStatement::setArray() -U- */ 559*cdf0e10cSrcweir void SAL_CALL OPreparedStatement::setArray(sal_Int32 parameter, const Reference< XArray >& /* x */) 560*cdf0e10cSrcweir throw(SQLException, RuntimeException) 561*cdf0e10cSrcweir { 562*cdf0e10cSrcweir OSL_TRACE("OPreparedStatement::setArray"); 563*cdf0e10cSrcweir MutexGuard aGuard(m_aMutex); 564*cdf0e10cSrcweir checkDisposed(OPreparedStatement::rBHelper.bDisposed); 565*cdf0e10cSrcweir checkParameterIndex(parameter); 566*cdf0e10cSrcweir 567*cdf0e10cSrcweir mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setArray", *this); 568*cdf0e10cSrcweir } 569*cdf0e10cSrcweir /* }}} */ 570*cdf0e10cSrcweir 571*cdf0e10cSrcweir 572*cdf0e10cSrcweir /* {{{ OPreparedStatement::setRef() -U- */ 573*cdf0e10cSrcweir void SAL_CALL OPreparedStatement::setRef(sal_Int32 parameter, const Reference< XRef >& /* x */) 574*cdf0e10cSrcweir throw(SQLException, RuntimeException) 575*cdf0e10cSrcweir { 576*cdf0e10cSrcweir OSL_TRACE("OPreparedStatement::setRef"); 577*cdf0e10cSrcweir MutexGuard aGuard(m_aMutex); 578*cdf0e10cSrcweir checkDisposed(OPreparedStatement::rBHelper.bDisposed); 579*cdf0e10cSrcweir checkParameterIndex(parameter); 580*cdf0e10cSrcweir 581*cdf0e10cSrcweir mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setRef", *this); 582*cdf0e10cSrcweir } 583*cdf0e10cSrcweir /* }}} */ 584*cdf0e10cSrcweir 585*cdf0e10cSrcweir namespace 586*cdf0e10cSrcweir { 587*cdf0e10cSrcweir template < class COMPLEXTYPE > 588*cdf0e10cSrcweir bool impl_setObject( const Reference< XParameters >& _rxParam, sal_Int32 _parameterIndex, const Any& _value, 589*cdf0e10cSrcweir void ( SAL_CALL XParameters::*_Setter )( sal_Int32, const COMPLEXTYPE& ), bool _throwIfNotExtractable ) 590*cdf0e10cSrcweir { 591*cdf0e10cSrcweir COMPLEXTYPE aValue; 592*cdf0e10cSrcweir if ( _value >>= aValue ) 593*cdf0e10cSrcweir { 594*cdf0e10cSrcweir (_rxParam.get()->*_Setter)( _parameterIndex, aValue ); 595*cdf0e10cSrcweir return true; 596*cdf0e10cSrcweir } 597*cdf0e10cSrcweir 598*cdf0e10cSrcweir if ( _throwIfNotExtractable ) 599*cdf0e10cSrcweir mysqlc_sdbc_driver::throwInvalidArgumentException( "OPreparedStatement::setObjectWithInfo", _rxParam ); 600*cdf0e10cSrcweir return false; 601*cdf0e10cSrcweir } 602*cdf0e10cSrcweir 603*cdf0e10cSrcweir template < class INTTYPE > 604*cdf0e10cSrcweir void impl_setObject( const Reference< XParameters >& _rxParam, sal_Int32 _parameterIndex, const Any& _value, 605*cdf0e10cSrcweir void ( SAL_CALL XParameters::*_Setter )( sal_Int32, INTTYPE ) ) 606*cdf0e10cSrcweir { 607*cdf0e10cSrcweir sal_Int32 nValue(0); 608*cdf0e10cSrcweir if ( !( _value >>= nValue ) ) 609*cdf0e10cSrcweir mysqlc_sdbc_driver::throwInvalidArgumentException( "OPreparedStatement::setObjectWithInfo", _rxParam ); 610*cdf0e10cSrcweir (_rxParam.get()->*_Setter)( _parameterIndex, (INTTYPE)nValue ); 611*cdf0e10cSrcweir } 612*cdf0e10cSrcweir } 613*cdf0e10cSrcweir 614*cdf0e10cSrcweir /* {{{ OPreparedStatement::setObjectWithInfo() -U- */ 615*cdf0e10cSrcweir void SAL_CALL OPreparedStatement::setObjectWithInfo(sal_Int32 _parameterIndex, const Any& _value, sal_Int32 _targetSqlType, sal_Int32 /* scale */) 616*cdf0e10cSrcweir throw(SQLException, RuntimeException) 617*cdf0e10cSrcweir { 618*cdf0e10cSrcweir OSL_TRACE("OPreparedStatement::setObjectWithInfo"); 619*cdf0e10cSrcweir checkDisposed(OPreparedStatement::rBHelper.bDisposed); 620*cdf0e10cSrcweir MutexGuard aGuard(m_aMutex); 621*cdf0e10cSrcweir checkParameterIndex( _parameterIndex ); 622*cdf0e10cSrcweir 623*cdf0e10cSrcweir if ( !_value.hasValue() ) 624*cdf0e10cSrcweir { 625*cdf0e10cSrcweir setNull( _parameterIndex, _targetSqlType ); 626*cdf0e10cSrcweir return; 627*cdf0e10cSrcweir } 628*cdf0e10cSrcweir 629*cdf0e10cSrcweir switch ( _targetSqlType ) 630*cdf0e10cSrcweir { 631*cdf0e10cSrcweir case DataType::DECIMAL: 632*cdf0e10cSrcweir case DataType::NUMERIC: 633*cdf0e10cSrcweir { 634*cdf0e10cSrcweir double nValue(0); 635*cdf0e10cSrcweir if ( _value >>= nValue ) 636*cdf0e10cSrcweir { 637*cdf0e10cSrcweir setDouble( _parameterIndex, nValue ); 638*cdf0e10cSrcweir break; 639*cdf0e10cSrcweir } 640*cdf0e10cSrcweir } 641*cdf0e10cSrcweir // run through 642*cdf0e10cSrcweir 643*cdf0e10cSrcweir case DataType::CHAR: 644*cdf0e10cSrcweir case DataType::VARCHAR: 645*cdf0e10cSrcweir case DataType::LONGVARCHAR: 646*cdf0e10cSrcweir impl_setObject( this, _parameterIndex, _value, &XParameters::setString, true ); 647*cdf0e10cSrcweir break; 648*cdf0e10cSrcweir 649*cdf0e10cSrcweir case DataType::BIGINT: 650*cdf0e10cSrcweir { 651*cdf0e10cSrcweir sal_Int64 nValue = 0; 652*cdf0e10cSrcweir if ( !( _value >>= nValue ) ) 653*cdf0e10cSrcweir mysqlc_sdbc_driver::throwInvalidArgumentException( "OPreparedStatement::setObjectWithInfo", *this ); 654*cdf0e10cSrcweir setLong( _parameterIndex, nValue ); 655*cdf0e10cSrcweir } 656*cdf0e10cSrcweir break; 657*cdf0e10cSrcweir 658*cdf0e10cSrcweir case DataType::FLOAT: 659*cdf0e10cSrcweir case DataType::REAL: 660*cdf0e10cSrcweir { 661*cdf0e10cSrcweir float nValue = 0; 662*cdf0e10cSrcweir if ( _value >>= nValue ) 663*cdf0e10cSrcweir { 664*cdf0e10cSrcweir setFloat(_parameterIndex,nValue); 665*cdf0e10cSrcweir break; 666*cdf0e10cSrcweir } 667*cdf0e10cSrcweir } 668*cdf0e10cSrcweir // run through if we couldn't set a float value 669*cdf0e10cSrcweir 670*cdf0e10cSrcweir case DataType::DOUBLE: 671*cdf0e10cSrcweir { 672*cdf0e10cSrcweir double nValue(0); 673*cdf0e10cSrcweir if ( !( _value >>= nValue ) ) 674*cdf0e10cSrcweir mysqlc_sdbc_driver::throwInvalidArgumentException( "OPreparedStatement::setObjectWithInfo", *this ); 675*cdf0e10cSrcweir setDouble( _parameterIndex, nValue ); 676*cdf0e10cSrcweir } 677*cdf0e10cSrcweir break; 678*cdf0e10cSrcweir 679*cdf0e10cSrcweir case DataType::DATE: 680*cdf0e10cSrcweir impl_setObject( this, _parameterIndex, _value, &XParameters::setDate, true ); 681*cdf0e10cSrcweir break; 682*cdf0e10cSrcweir 683*cdf0e10cSrcweir case DataType::TIME: 684*cdf0e10cSrcweir impl_setObject( this, _parameterIndex, _value, &XParameters::setTime, true ); 685*cdf0e10cSrcweir break; 686*cdf0e10cSrcweir 687*cdf0e10cSrcweir case DataType::TIMESTAMP: 688*cdf0e10cSrcweir impl_setObject( this, _parameterIndex, _value, &XParameters::setTimestamp, true ); 689*cdf0e10cSrcweir break; 690*cdf0e10cSrcweir 691*cdf0e10cSrcweir case DataType::BINARY: 692*cdf0e10cSrcweir case DataType::VARBINARY: 693*cdf0e10cSrcweir case DataType::LONGVARBINARY: 694*cdf0e10cSrcweir { 695*cdf0e10cSrcweir if ( impl_setObject( this, _parameterIndex, _value, &XParameters::setBytes, false ) 696*cdf0e10cSrcweir || impl_setObject( this, _parameterIndex, _value, &XParameters::setBlob, false ) 697*cdf0e10cSrcweir || impl_setObject( this, _parameterIndex, _value, &XParameters::setClob, false ) 698*cdf0e10cSrcweir ) 699*cdf0e10cSrcweir break; 700*cdf0e10cSrcweir 701*cdf0e10cSrcweir Reference< ::com::sun::star::io::XInputStream > xBinStream; 702*cdf0e10cSrcweir if ( _value >>= xBinStream ) 703*cdf0e10cSrcweir { 704*cdf0e10cSrcweir setBinaryStream( _parameterIndex, xBinStream, xBinStream->available() ); 705*cdf0e10cSrcweir break; 706*cdf0e10cSrcweir } 707*cdf0e10cSrcweir 708*cdf0e10cSrcweir mysqlc_sdbc_driver::throwInvalidArgumentException( "OPreparedStatement::setObjectWithInfo", *this ); 709*cdf0e10cSrcweir } 710*cdf0e10cSrcweir break; 711*cdf0e10cSrcweir 712*cdf0e10cSrcweir case DataType::BIT: 713*cdf0e10cSrcweir case DataType::BOOLEAN: 714*cdf0e10cSrcweir { 715*cdf0e10cSrcweir bool bValue( false ); 716*cdf0e10cSrcweir if ( _value >>= bValue ) 717*cdf0e10cSrcweir { 718*cdf0e10cSrcweir setBoolean( _parameterIndex, bValue ); 719*cdf0e10cSrcweir break; 720*cdf0e10cSrcweir } 721*cdf0e10cSrcweir sal_Int32 nValue( 0 ); 722*cdf0e10cSrcweir if ( _value >>= nValue ) 723*cdf0e10cSrcweir { 724*cdf0e10cSrcweir setBoolean( _parameterIndex, ( nValue != 0 ) ); 725*cdf0e10cSrcweir break; 726*cdf0e10cSrcweir } 727*cdf0e10cSrcweir mysqlc_sdbc_driver::throwInvalidArgumentException( "OPreparedStatement::setObjectWithInfo", *this ); 728*cdf0e10cSrcweir } 729*cdf0e10cSrcweir break; 730*cdf0e10cSrcweir 731*cdf0e10cSrcweir case DataType::TINYINT: 732*cdf0e10cSrcweir impl_setObject( this, _parameterIndex, _value, &XParameters::setByte ); 733*cdf0e10cSrcweir break; 734*cdf0e10cSrcweir 735*cdf0e10cSrcweir case DataType::SMALLINT: 736*cdf0e10cSrcweir impl_setObject( this, _parameterIndex, _value, &XParameters::setShort ); 737*cdf0e10cSrcweir break; 738*cdf0e10cSrcweir 739*cdf0e10cSrcweir case DataType::INTEGER: 740*cdf0e10cSrcweir impl_setObject( this, _parameterIndex, _value, &XParameters::setInt ); 741*cdf0e10cSrcweir break; 742*cdf0e10cSrcweir 743*cdf0e10cSrcweir default: 744*cdf0e10cSrcweir mysqlc_sdbc_driver::throwInvalidArgumentException( "OPreparedStatement::setObjectWithInfo", *this ); 745*cdf0e10cSrcweir break; 746*cdf0e10cSrcweir } 747*cdf0e10cSrcweir } 748*cdf0e10cSrcweir /* }}} */ 749*cdf0e10cSrcweir 750*cdf0e10cSrcweir 751*cdf0e10cSrcweir /* {{{ OPreparedStatement::setObjectNull() -U- */ 752*cdf0e10cSrcweir void SAL_CALL OPreparedStatement::setObjectNull(sal_Int32 parameter, sal_Int32 /* sqlType */, const OUString& /* typeName */) 753*cdf0e10cSrcweir throw(SQLException, RuntimeException) 754*cdf0e10cSrcweir { 755*cdf0e10cSrcweir OSL_TRACE("OPreparedStatement::setObjectNull"); 756*cdf0e10cSrcweir MutexGuard aGuard(m_aMutex); 757*cdf0e10cSrcweir checkDisposed(OPreparedStatement::rBHelper.bDisposed); 758*cdf0e10cSrcweir checkParameterIndex(parameter); 759*cdf0e10cSrcweir 760*cdf0e10cSrcweir mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setObjectNull", *this); 761*cdf0e10cSrcweir } 762*cdf0e10cSrcweir /* }}} */ 763*cdf0e10cSrcweir 764*cdf0e10cSrcweir 765*cdf0e10cSrcweir /* {{{ OPreparedStatement::setObject() -U- */ 766*cdf0e10cSrcweir void SAL_CALL OPreparedStatement::setObject(sal_Int32 parameter, const Any& /* x */) 767*cdf0e10cSrcweir throw(SQLException, RuntimeException) 768*cdf0e10cSrcweir { 769*cdf0e10cSrcweir OSL_TRACE("OPreparedStatement::setObject"); 770*cdf0e10cSrcweir MutexGuard aGuard(m_aMutex); 771*cdf0e10cSrcweir checkDisposed(OPreparedStatement::rBHelper.bDisposed); 772*cdf0e10cSrcweir checkParameterIndex(parameter); 773*cdf0e10cSrcweir 774*cdf0e10cSrcweir mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setObject", *this); 775*cdf0e10cSrcweir } 776*cdf0e10cSrcweir /* }}} */ 777*cdf0e10cSrcweir 778*cdf0e10cSrcweir 779*cdf0e10cSrcweir /* {{{ OPreparedStatement::setShort() -I- */ 780*cdf0e10cSrcweir void SAL_CALL OPreparedStatement::setShort(sal_Int32 parameter, sal_Int16 x) 781*cdf0e10cSrcweir throw(SQLException, RuntimeException) 782*cdf0e10cSrcweir { 783*cdf0e10cSrcweir OSL_TRACE("OPreparedStatement::setShort"); 784*cdf0e10cSrcweir MutexGuard aGuard(m_aMutex); 785*cdf0e10cSrcweir checkDisposed(OPreparedStatement::rBHelper.bDisposed); 786*cdf0e10cSrcweir checkParameterIndex(parameter); 787*cdf0e10cSrcweir 788*cdf0e10cSrcweir try { 789*cdf0e10cSrcweir ((sql::PreparedStatement *)cppStatement)->setInt(parameter, x); 790*cdf0e10cSrcweir } catch (sql::MethodNotImplementedException) { 791*cdf0e10cSrcweir mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setShort", *this); 792*cdf0e10cSrcweir } catch (sql::SQLException &e) { 793*cdf0e10cSrcweir mysqlc_sdbc_driver::translateAndThrow(e, *this, m_pConnection->getConnectionEncoding()); 794*cdf0e10cSrcweir } 795*cdf0e10cSrcweir } 796*cdf0e10cSrcweir /* }}} */ 797*cdf0e10cSrcweir 798*cdf0e10cSrcweir 799*cdf0e10cSrcweir /* {{{ OPreparedStatement::setBytes() -I- */ 800*cdf0e10cSrcweir void SAL_CALL OPreparedStatement::setBytes(sal_Int32 parameter, const Sequence< sal_Int8 >& x) 801*cdf0e10cSrcweir throw(SQLException, RuntimeException) 802*cdf0e10cSrcweir { 803*cdf0e10cSrcweir OSL_TRACE("OPreparedStatement::setBytes"); 804*cdf0e10cSrcweir MutexGuard aGuard(m_aMutex); 805*cdf0e10cSrcweir checkDisposed(OPreparedStatement::rBHelper.bDisposed); 806*cdf0e10cSrcweir checkParameterIndex(parameter); 807*cdf0e10cSrcweir 808*cdf0e10cSrcweir ext_std::string blobby((char *)x.getConstArray(), x.getLength()); 809*cdf0e10cSrcweir try { 810*cdf0e10cSrcweir ((sql::PreparedStatement *)cppStatement)->setString(parameter, blobby); 811*cdf0e10cSrcweir } catch (sql::MethodNotImplementedException) { 812*cdf0e10cSrcweir mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setBytes", *this); 813*cdf0e10cSrcweir } catch (sql::SQLException &e) { 814*cdf0e10cSrcweir mysqlc_sdbc_driver::translateAndThrow(e, *this, m_pConnection->getConnectionEncoding()); 815*cdf0e10cSrcweir } 816*cdf0e10cSrcweir } 817*cdf0e10cSrcweir /* }}} */ 818*cdf0e10cSrcweir 819*cdf0e10cSrcweir 820*cdf0e10cSrcweir /* {{{ OPreparedStatement::setCharacterStream() -U- */ 821*cdf0e10cSrcweir void SAL_CALL OPreparedStatement::setCharacterStream(sal_Int32 parameter, 822*cdf0e10cSrcweir const Reference< XInputStream >& /* x */, 823*cdf0e10cSrcweir sal_Int32 /* length */) 824*cdf0e10cSrcweir throw(SQLException, RuntimeException) 825*cdf0e10cSrcweir { 826*cdf0e10cSrcweir OSL_TRACE("OPreparedStatement::setCharacterStream"); 827*cdf0e10cSrcweir MutexGuard aGuard(m_aMutex); 828*cdf0e10cSrcweir checkDisposed(OPreparedStatement::rBHelper.bDisposed); 829*cdf0e10cSrcweir checkParameterIndex(parameter); 830*cdf0e10cSrcweir 831*cdf0e10cSrcweir mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setCharacterStream", *this); 832*cdf0e10cSrcweir } 833*cdf0e10cSrcweir /* }}} */ 834*cdf0e10cSrcweir 835*cdf0e10cSrcweir 836*cdf0e10cSrcweir /* {{{ OPreparedStatement::setBinaryStream() -U- */ 837*cdf0e10cSrcweir void SAL_CALL OPreparedStatement::setBinaryStream(sal_Int32 parameter, 838*cdf0e10cSrcweir const Reference< XInputStream >& /* x */, 839*cdf0e10cSrcweir sal_Int32 /* length */) 840*cdf0e10cSrcweir throw(SQLException, RuntimeException) 841*cdf0e10cSrcweir { 842*cdf0e10cSrcweir OSL_TRACE("OPreparedStatement::setBinaryStream"); 843*cdf0e10cSrcweir MutexGuard aGuard(m_aMutex); 844*cdf0e10cSrcweir checkDisposed(OPreparedStatement::rBHelper.bDisposed); 845*cdf0e10cSrcweir checkParameterIndex(parameter); 846*cdf0e10cSrcweir 847*cdf0e10cSrcweir mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setBinaryStream", *this); 848*cdf0e10cSrcweir } 849*cdf0e10cSrcweir /* }}} */ 850*cdf0e10cSrcweir 851*cdf0e10cSrcweir 852*cdf0e10cSrcweir /* {{{ OPreparedStatement::clearParameters() -I- */ 853*cdf0e10cSrcweir void SAL_CALL OPreparedStatement::clearParameters() 854*cdf0e10cSrcweir throw(SQLException, RuntimeException) 855*cdf0e10cSrcweir { 856*cdf0e10cSrcweir OSL_TRACE("OPreparedStatement::clearParameters"); 857*cdf0e10cSrcweir MutexGuard aGuard(m_aMutex); 858*cdf0e10cSrcweir checkDisposed(OPreparedStatement::rBHelper.bDisposed); 859*cdf0e10cSrcweir 860*cdf0e10cSrcweir try { 861*cdf0e10cSrcweir ((sql::PreparedStatement *)cppStatement)->clearParameters(); 862*cdf0e10cSrcweir } catch (sql::MethodNotImplementedException) { 863*cdf0e10cSrcweir mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::clearParameters", *this); 864*cdf0e10cSrcweir } catch (sql::SQLException &e) { 865*cdf0e10cSrcweir mysqlc_sdbc_driver::translateAndThrow(e, *this, m_pConnection->getConnectionEncoding()); 866*cdf0e10cSrcweir } 867*cdf0e10cSrcweir } 868*cdf0e10cSrcweir /* }}} */ 869*cdf0e10cSrcweir 870*cdf0e10cSrcweir 871*cdf0e10cSrcweir /* {{{ OPreparedStatement::clearBatch() -U- */ 872*cdf0e10cSrcweir void SAL_CALL OPreparedStatement::clearBatch() 873*cdf0e10cSrcweir throw(SQLException, RuntimeException) 874*cdf0e10cSrcweir { 875*cdf0e10cSrcweir OSL_TRACE("OPreparedStatement::clearBatch"); 876*cdf0e10cSrcweir mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::clearBatch", *this); 877*cdf0e10cSrcweir } 878*cdf0e10cSrcweir /* }}} */ 879*cdf0e10cSrcweir 880*cdf0e10cSrcweir 881*cdf0e10cSrcweir /* {{{ OPreparedStatement::addBatch() -U- */ 882*cdf0e10cSrcweir void SAL_CALL OPreparedStatement::addBatch() 883*cdf0e10cSrcweir throw(SQLException, RuntimeException) 884*cdf0e10cSrcweir { 885*cdf0e10cSrcweir OSL_TRACE("OPreparedStatement::addBatch"); 886*cdf0e10cSrcweir mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::addBatch", *this); 887*cdf0e10cSrcweir } 888*cdf0e10cSrcweir /* }}} */ 889*cdf0e10cSrcweir 890*cdf0e10cSrcweir 891*cdf0e10cSrcweir /* {{{ OPreparedStatement::executeBatch() -I- */ 892*cdf0e10cSrcweir Sequence< sal_Int32 > SAL_CALL OPreparedStatement::executeBatch() 893*cdf0e10cSrcweir throw(SQLException, RuntimeException) 894*cdf0e10cSrcweir { 895*cdf0e10cSrcweir OSL_TRACE("OPreparedStatement::executeBatch"); 896*cdf0e10cSrcweir Sequence< sal_Int32 > aRet= Sequence< sal_Int32 > (); 897*cdf0e10cSrcweir return aRet; 898*cdf0e10cSrcweir } 899*cdf0e10cSrcweir /* }}} */ 900*cdf0e10cSrcweir 901*cdf0e10cSrcweir 902*cdf0e10cSrcweir /* {{{ OPreparedStatement::setFastPropertyValue_NoBroadcast() -I- */ 903*cdf0e10cSrcweir void OPreparedStatement::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any& rValue) 904*cdf0e10cSrcweir throw(Exception) 905*cdf0e10cSrcweir { 906*cdf0e10cSrcweir OSL_TRACE("OPreparedStatement::setFastPropertyValue_NoBroadcast"); 907*cdf0e10cSrcweir switch(nHandle) 908*cdf0e10cSrcweir { 909*cdf0e10cSrcweir case PROPERTY_ID_RESULTSETCONCURRENCY: 910*cdf0e10cSrcweir break; 911*cdf0e10cSrcweir case PROPERTY_ID_RESULTSETTYPE: 912*cdf0e10cSrcweir break; 913*cdf0e10cSrcweir case PROPERTY_ID_FETCHDIRECTION: 914*cdf0e10cSrcweir break; 915*cdf0e10cSrcweir case PROPERTY_ID_USEBOOKMARKS: 916*cdf0e10cSrcweir break; 917*cdf0e10cSrcweir default: 918*cdf0e10cSrcweir /* XXX: Recursion ?? */ 919*cdf0e10cSrcweir OPreparedStatement::setFastPropertyValue_NoBroadcast(nHandle,rValue); 920*cdf0e10cSrcweir } 921*cdf0e10cSrcweir } 922*cdf0e10cSrcweir /* }}} */ 923*cdf0e10cSrcweir 924*cdf0e10cSrcweir 925*cdf0e10cSrcweir /* {{{ OPreparedStatement::checkParameterIndex() -I- */ 926*cdf0e10cSrcweir void OPreparedStatement::checkParameterIndex(sal_Int32 column) 927*cdf0e10cSrcweir { 928*cdf0e10cSrcweir OSL_TRACE("OPreparedStatement::checkColumnIndex"); 929*cdf0e10cSrcweir if (column < 1 || column > (sal_Int32) m_paramCount) { 930*cdf0e10cSrcweir OUString buf( RTL_CONSTASCII_USTRINGPARAM( "Parameter index out of range" ) ); 931*cdf0e10cSrcweir throw SQLException(buf, *this, OUString(), 1, Any ()); 932*cdf0e10cSrcweir } 933*cdf0e10cSrcweir } 934*cdf0e10cSrcweir /* }}} */ 935*cdf0e10cSrcweir 936*cdf0e10cSrcweir 937*cdf0e10cSrcweir /* 938*cdf0e10cSrcweir * Local variables: 939*cdf0e10cSrcweir * tab-width: 4 940*cdf0e10cSrcweir * c-basic-offset: 4 941*cdf0e10cSrcweir * End: 942*cdf0e10cSrcweir * vim600: noet sw=4 ts=4 fdm=marker 943*cdf0e10cSrcweir * vim<600: noet sw=4 ts=4 944*cdf0e10cSrcweir */ 945