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