bump product version to 5.0.4.1
[LibreOffice.git] / mysqlc / source / mysqlc_preparedstatement.cxx
blob7736e7386d8c1f7676837a781f763bebf034cc48
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "mysqlc_general.hxx"
21 #include "mysqlc_preparedstatement.hxx"
22 #include "mysqlc_propertyids.hxx"
23 #include "mysqlc_resultsetmetadata.hxx"
25 #include <com/sun/star/lang/DisposedException.hpp>
26 #include <com/sun/star/sdbc/DataType.hpp>
28 #include <cppconn/connection.h>
29 #include <cppconn/exception.h>
30 #include <cppconn/parameter_metadata.h>
31 #include <cppconn/prepared_statement.h>
32 #include <cppconn/statement.h>
33 #include <cppuhelper/typeprovider.hxx>
34 #include <osl/diagnose.h>
36 #include <stdio.h>
38 #ifdef _MSC_VER
39 #define snprintf _snprintf
40 #endif
42 using namespace connectivity::mysqlc;
43 using namespace com::sun::star::uno;
44 using namespace com::sun::star::lang;
45 using namespace com::sun::star::beans;
46 using namespace com::sun::star::sdbc;
47 using namespace com::sun::star::container;
48 using namespace com::sun::star::io;
49 using namespace com::sun::star::util;
50 using ::osl::MutexGuard;
51 using mysqlc_sdbc_driver::getStringFromAny;
54 static inline char * my_i_to_a(char * buf, size_t buf_size, int a)
56 snprintf(buf, buf_size, "%d", a);
57 return buf;
60 rtl::OUString OPreparedStatement::getImplementationName()
61 throw (css::uno::RuntimeException, std::exception)
63 return rtl::OUString("com.sun.star.sdbcx.mysqlc.PreparedStatement");
66 css::uno::Sequence<rtl::OUString> OPreparedStatement::getSupportedServiceNames()
67 throw (css::uno::RuntimeException, std::exception)
69 css::uno::Sequence<rtl::OUString> s(1);
70 s[0] = "com.sun.star.sdbc.PreparedStatement";
71 return s;
74 sal_Bool OPreparedStatement::supportsService(rtl::OUString const & ServiceName)
75 throw (css::uno::RuntimeException, std::exception)
77 return cppu::supportsService(this, ServiceName);
80 OPreparedStatement::OPreparedStatement(OConnection* _pConnection, sql::PreparedStatement * _cppPrepStmt)
81 :OCommonStatement(_pConnection, _cppPrepStmt)
83 OSL_TRACE("OPreparedStatement::OPreparedStatement");
84 m_pConnection = _pConnection;
85 m_pConnection->acquire();
87 try {
88 m_paramCount = static_cast<sql::PreparedStatement *>(cppStatement)->getParameterMetaData()->getParameterCount();
89 } catch (const sql::SQLException &e) {
90 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_pConnection->getConnectionEncoding());
94 OPreparedStatement::~OPreparedStatement()
96 OSL_TRACE("OPreparedStatement::~OPreparedStatement");
99 void SAL_CALL OPreparedStatement::acquire()
100 throw()
102 OSL_TRACE("OPreparedStatement::acquire");
103 OCommonStatement::acquire();
106 void SAL_CALL OPreparedStatement::release()
107 throw()
109 OSL_TRACE("OPreparedStatement::release");
110 OCommonStatement::release();
113 Any SAL_CALL OPreparedStatement::queryInterface(const Type & rType)
114 throw(RuntimeException, std::exception)
116 OSL_TRACE("OPreparedStatement::queryInterface");
117 Any aRet = OCommonStatement::queryInterface(rType);
118 if (!aRet.hasValue()) {
119 aRet = OPreparedStatement_BASE::queryInterface(rType);
121 return aRet;
124 Sequence< Type > SAL_CALL OPreparedStatement::getTypes()
125 throw(RuntimeException, std::exception)
127 OSL_TRACE("OPreparedStatement::getTypes");
128 return concatSequences(OPreparedStatement_BASE::getTypes(), OCommonStatement::getTypes());
131 Reference< XResultSetMetaData > SAL_CALL OPreparedStatement::getMetaData()
132 throw(SQLException, RuntimeException, std::exception)
134 OSL_TRACE("OPreparedStatement::getMetaData");
135 MutexGuard aGuard(m_aMutex);
136 checkDisposed(OPreparedStatement::rBHelper.bDisposed);
138 try {
139 if (!m_xMetaData.is()) {
140 m_xMetaData = new OResultSetMetaData(
141 static_cast<sql::PreparedStatement *>(cppStatement)->getMetaData(),
142 getOwnConnection()->getConnectionEncoding()
145 } catch (const sql::MethodNotImplementedException &) {
146 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::getMetaData", *this);
147 } catch (const sql::SQLException &e) {
148 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_pConnection->getConnectionEncoding());
150 return m_xMetaData;
153 void SAL_CALL OPreparedStatement::close()
154 throw(SQLException, RuntimeException, std::exception)
156 OSL_TRACE("OPreparedStatement::close");
158 MutexGuard aGuard(m_aMutex);
159 checkDisposed(OPreparedStatement::rBHelper.bDisposed);
161 try {
162 clearWarnings();
163 clearParameters();
164 OCommonStatement::close();
165 } catch (const SQLException &) {
166 // If we get an error, ignore
169 // Remove this Statement object from the Connection object's
170 // list
173 sal_Bool SAL_CALL OPreparedStatement::execute()
174 throw(SQLException, RuntimeException, std::exception)
176 OSL_TRACE("OPreparedStatement::execute");
177 MutexGuard aGuard(m_aMutex);
178 checkDisposed(OPreparedStatement::rBHelper.bDisposed);
180 bool success = false;
181 try {
182 success = static_cast<sql::PreparedStatement *>(cppStatement)->execute();
183 } catch (const sql::SQLException &e) {
184 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_pConnection->getConnectionEncoding());
186 return success;
189 sal_Int32 SAL_CALL OPreparedStatement::executeUpdate()
190 throw(SQLException, RuntimeException, std::exception)
192 OSL_TRACE("OPreparedStatement::executeUpdate");
193 MutexGuard aGuard(m_aMutex);
194 checkDisposed(OPreparedStatement::rBHelper.bDisposed);
196 sal_Int32 affectedRows = 0;
197 try {
198 affectedRows = static_cast<sql::PreparedStatement *>(cppStatement)->executeUpdate();
199 } catch (const sql::SQLException &e) {
200 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_pConnection->getConnectionEncoding());
202 return affectedRows;
205 void SAL_CALL OPreparedStatement::setString(sal_Int32 parameter, const rtl::OUString& x)
206 throw(SQLException, RuntimeException, std::exception)
208 OSL_TRACE("OPreparedStatement::setString");
209 MutexGuard aGuard(m_aMutex);
210 checkDisposed(OPreparedStatement::rBHelper.bDisposed);
211 checkParameterIndex(parameter);
213 try {
214 std::string stringie(rtl::OUStringToOString(x, m_pConnection->getConnectionEncoding()).getStr());
215 static_cast<sql::PreparedStatement *>(cppStatement)->setString(parameter, stringie);
216 } catch (const sql::MethodNotImplementedException &) {
217 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::clearParameters", *this);
218 } catch (const sql::SQLException &e) {
219 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_pConnection->getConnectionEncoding());
223 Reference< XConnection > SAL_CALL OPreparedStatement::getConnection()
224 throw(SQLException, RuntimeException, std::exception)
226 OSL_TRACE("OPreparedStatement::getConnection");
227 MutexGuard aGuard(m_aMutex);
228 checkDisposed(OPreparedStatement::rBHelper.bDisposed);
230 return m_pConnection;
233 Reference< XResultSet > SAL_CALL OPreparedStatement::executeQuery(const rtl::OUString& sql)
234 throw(SQLException, RuntimeException, std::exception)
236 return OCommonStatement::executeQuery( sql );
239 sal_Int32 SAL_CALL OPreparedStatement::executeUpdate(const rtl::OUString& sql)
240 throw(SQLException, RuntimeException, std::exception)
242 return OCommonStatement::executeUpdate( sql );
245 sal_Bool SAL_CALL OPreparedStatement::execute( const rtl::OUString& sql )
246 throw(SQLException, RuntimeException, std::exception)
248 return OCommonStatement::execute( sql );
251 Reference< XResultSet > SAL_CALL OPreparedStatement::executeQuery()
252 throw(SQLException, RuntimeException, std::exception)
254 OSL_TRACE("OPreparedStatement::executeQuery");
255 MutexGuard aGuard(m_aMutex);
256 checkDisposed(OPreparedStatement::rBHelper.bDisposed);
258 Reference< XResultSet > xResultSet;
259 try {
260 sql::ResultSet * res = static_cast<sql::PreparedStatement *>(cppStatement)->executeQuery();
261 xResultSet = new OResultSet(this, res, getOwnConnection()->getConnectionEncoding());
262 } catch (const sql::SQLException &e) {
263 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_pConnection->getConnectionEncoding());
265 return xResultSet;
268 void SAL_CALL OPreparedStatement::setBoolean(sal_Int32 parameter, sal_Bool x)
269 throw(SQLException, RuntimeException, std::exception)
271 OSL_TRACE("OPreparedStatement::setBoolean");
272 MutexGuard aGuard(m_aMutex);
273 checkDisposed(OPreparedStatement::rBHelper.bDisposed);
274 checkParameterIndex(parameter);
276 try {
277 static_cast<sql::PreparedStatement *>(cppStatement)->setBoolean(parameter, x);
278 } catch (const sql::MethodNotImplementedException &) {
279 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setBoolean", *this);
280 } catch (const sql::SQLException &e) {
281 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_pConnection->getConnectionEncoding());
285 void SAL_CALL OPreparedStatement::setByte(sal_Int32 parameter, sal_Int8 x)
286 throw(SQLException, RuntimeException, std::exception)
288 OSL_TRACE("OPreparedStatement::setByte");
289 MutexGuard aGuard(m_aMutex);
290 checkDisposed(OPreparedStatement::rBHelper.bDisposed);
291 checkParameterIndex(parameter);
293 try {
294 static_cast<sql::PreparedStatement *>(cppStatement)->setInt(parameter, x);
295 } catch (const sql::MethodNotImplementedException &) {
296 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setByte", *this);
297 } catch (const sql::SQLException &e) {
298 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_pConnection->getConnectionEncoding());
302 void SAL_CALL OPreparedStatement::setDate(sal_Int32 parameter, const Date& aData)
303 throw(SQLException, RuntimeException, std::exception)
305 OSL_TRACE("OPreparedStatement::setDate");
306 MutexGuard aGuard(m_aMutex);
307 checkDisposed(OPreparedStatement::rBHelper.bDisposed);
308 checkParameterIndex(parameter);
310 std::string dateStr;
311 char buf[20];
312 dateStr.append(my_i_to_a(buf, sizeof(buf)-1, aData.Year));
313 dateStr.append("-", 1);
314 dateStr.append(my_i_to_a(buf, sizeof(buf)-1, aData.Month));
315 dateStr.append("-", 1);
316 dateStr.append(my_i_to_a(buf, sizeof(buf)-1, aData.Day));
318 try {
319 static_cast<sql::PreparedStatement *>(cppStatement)->setDateTime(parameter, dateStr);
320 } catch (const sql::MethodNotImplementedException &) {
321 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setDate", *this);
322 } catch (const sql::SQLException &e) {
323 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_pConnection->getConnectionEncoding());
327 void SAL_CALL OPreparedStatement::setTime(sal_Int32 parameter, const Time& aVal)
328 throw(SQLException, RuntimeException, std::exception)
330 OSL_TRACE("OPreparedStatement::setTime");
331 MutexGuard aGuard(m_aMutex);
332 checkDisposed(OPreparedStatement::rBHelper.bDisposed);
333 checkParameterIndex(parameter);
335 std::string timeStr;
336 char buf[20];
337 timeStr.append(my_i_to_a(buf, sizeof(buf)-1, aVal.Hours));
338 timeStr.append(":", 1);
339 timeStr.append(my_i_to_a(buf, sizeof(buf)-1, aVal.Minutes));
340 timeStr.append(":", 1);
341 timeStr.append(my_i_to_a(buf, sizeof(buf)-1, aVal.Seconds));
343 try {
344 static_cast<sql::PreparedStatement *>(cppStatement)->setDateTime(parameter, timeStr);
345 } catch (const sql::MethodNotImplementedException &) {
346 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setTime", *this);
347 } catch (const sql::SQLException &e) {
348 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_pConnection->getConnectionEncoding());
352 void SAL_CALL OPreparedStatement::setTimestamp(sal_Int32 parameter, const DateTime& aVal)
353 throw(SQLException, RuntimeException, std::exception)
355 OSL_TRACE("OPreparedStatement::setTimestamp");
356 MutexGuard aGuard(m_aMutex);
357 checkDisposed(OPreparedStatement::rBHelper.bDisposed);
358 checkParameterIndex(parameter);
360 std::string timeStr;
361 char buf[20];
362 timeStr.append(my_i_to_a(buf, sizeof(buf)-1, aVal.Year));
363 timeStr.append("-", 1);
364 timeStr.append(my_i_to_a(buf, sizeof(buf)-1, aVal.Month));
365 timeStr.append("-", 1);
366 timeStr.append(my_i_to_a(buf, sizeof(buf)-1, aVal.Day));
368 timeStr.append(" ", 1);
370 timeStr.append(my_i_to_a(buf, sizeof(buf)-1, aVal.Hours));
371 timeStr.append(":", 1);
372 timeStr.append(my_i_to_a(buf, sizeof(buf)-1, aVal.Minutes));
373 timeStr.append(":", 1);
374 timeStr.append(my_i_to_a(buf, sizeof(buf)-1, aVal.Seconds));
376 try {
377 static_cast<sql::PreparedStatement *>(cppStatement)->setDateTime(parameter, timeStr);
378 } catch (const sql::MethodNotImplementedException &) {
379 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setTimestamp", *this);
380 } catch (const sql::SQLException &e) {
381 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_pConnection->getConnectionEncoding());
385 void SAL_CALL OPreparedStatement::setDouble(sal_Int32 parameter, double x)
386 throw(SQLException, RuntimeException, std::exception)
388 OSL_TRACE("OPreparedStatement::setDouble");
389 MutexGuard aGuard(m_aMutex);
390 checkDisposed(OPreparedStatement::rBHelper.bDisposed);
391 checkParameterIndex(parameter);
393 try {
394 static_cast<sql::PreparedStatement *>(cppStatement)->setDouble(parameter, x);
395 } catch (const sql::MethodNotImplementedException &) {
396 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setDouble", *this);
397 } catch (const sql::SQLException &e) {
398 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_pConnection->getConnectionEncoding());
402 void SAL_CALL OPreparedStatement::setFloat(sal_Int32 parameter, float x)
403 throw(SQLException, RuntimeException, std::exception)
405 OSL_TRACE("OPreparedStatement::setFloat");
406 MutexGuard aGuard(m_aMutex);
407 checkDisposed(OPreparedStatement::rBHelper.bDisposed);
408 checkParameterIndex(parameter);
410 try {
411 static_cast<sql::PreparedStatement *>(cppStatement)->setDouble(parameter, x);
412 } catch (const sql::MethodNotImplementedException &) {
413 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setFloat", *this);
414 } catch (const sql::SQLException &e) {
415 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_pConnection->getConnectionEncoding());
419 void SAL_CALL OPreparedStatement::setInt(sal_Int32 parameter, sal_Int32 x)
420 throw(SQLException, RuntimeException, std::exception)
422 OSL_TRACE("OPreparedStatement::setInt");
423 MutexGuard aGuard(m_aMutex);
424 checkDisposed(OPreparedStatement::rBHelper.bDisposed);
425 checkParameterIndex(parameter);
427 try {
428 static_cast<sql::PreparedStatement *>(cppStatement)->setInt(parameter, x);
429 } catch (const sql::MethodNotImplementedException &) {
430 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setInt", *this);
431 } catch (const sql::SQLException &e) {
432 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_pConnection->getConnectionEncoding());
436 void SAL_CALL OPreparedStatement::setLong(sal_Int32 parameter, sal_Int64 aVal)
437 throw(SQLException, RuntimeException, std::exception)
439 OSL_TRACE("OPreparedStatement::setLong");
440 MutexGuard aGuard(m_aMutex);
441 checkDisposed(OPreparedStatement::rBHelper.bDisposed);
442 checkParameterIndex(parameter);
444 try {
445 static_cast<sql::PreparedStatement *>(cppStatement)->setInt64(parameter, aVal);
446 } catch (const sql::MethodNotImplementedException &) {
447 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setLong", *this);
448 } catch (const sql::SQLException &e) {
449 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_pConnection->getConnectionEncoding());
453 void SAL_CALL OPreparedStatement::setNull(sal_Int32 parameter, sal_Int32 sqlType)
454 throw(SQLException, RuntimeException, std::exception)
456 OSL_TRACE("OPreparedStatement::setNull");
457 MutexGuard aGuard(m_aMutex);
458 checkDisposed(OPreparedStatement::rBHelper.bDisposed);
459 checkParameterIndex(parameter);
461 try {
462 static_cast<sql::PreparedStatement *>(cppStatement)->setNull(parameter, sqlType);
463 } catch (const sql::MethodNotImplementedException &) {
464 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setNull", *this);
465 } catch (const sql::SQLException &e) {
466 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_pConnection->getConnectionEncoding());
470 void SAL_CALL OPreparedStatement::setClob(sal_Int32 parameter, const Reference< XClob >& /* x */)
471 throw(SQLException, RuntimeException, std::exception)
473 OSL_TRACE("OPreparedStatement::setClob");
474 MutexGuard aGuard(m_aMutex);
475 checkDisposed(OPreparedStatement::rBHelper.bDisposed);
476 checkParameterIndex(parameter);
478 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setClob", *this);
481 void SAL_CALL OPreparedStatement::setBlob(sal_Int32 parameter, const Reference< XBlob >& /* x */)
482 throw(SQLException, RuntimeException, std::exception)
484 OSL_TRACE("OPreparedStatement::setBlob");
485 MutexGuard aGuard(m_aMutex);
486 checkDisposed(OPreparedStatement::rBHelper.bDisposed);
487 checkParameterIndex(parameter);
489 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setBlob", *this);
492 void SAL_CALL OPreparedStatement::setArray(sal_Int32 parameter, const Reference< XArray >& /* x */)
493 throw(SQLException, RuntimeException, std::exception)
495 OSL_TRACE("OPreparedStatement::setArray");
496 MutexGuard aGuard(m_aMutex);
497 checkDisposed(OPreparedStatement::rBHelper.bDisposed);
498 checkParameterIndex(parameter);
500 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setArray", *this);
503 void SAL_CALL OPreparedStatement::setRef(sal_Int32 parameter, const Reference< XRef >& /* x */)
504 throw(SQLException, RuntimeException, std::exception)
506 OSL_TRACE("OPreparedStatement::setRef");
507 MutexGuard aGuard(m_aMutex);
508 checkDisposed(OPreparedStatement::rBHelper.bDisposed);
509 checkParameterIndex(parameter);
511 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setRef", *this);
514 namespace
516 template < class COMPLEXTYPE >
517 bool impl_setObject( const Reference< XParameters >& _rxParam, sal_Int32 _parameterIndex, const Any& _value,
518 void ( SAL_CALL XParameters::*_Setter )( sal_Int32, const COMPLEXTYPE& ), bool _throwIfNotExtractable )
520 COMPLEXTYPE aValue;
521 if ( _value >>= aValue )
523 (_rxParam.get()->*_Setter)( _parameterIndex, aValue );
524 return true;
527 if ( _throwIfNotExtractable )
528 mysqlc_sdbc_driver::throwInvalidArgumentException( "OPreparedStatement::setObjectWithInfo", _rxParam );
529 return false;
532 template < class INTTYPE >
533 void impl_setObject( const Reference< XParameters >& _rxParam, sal_Int32 _parameterIndex, const Any& _value,
534 void ( SAL_CALL XParameters::*_Setter )( sal_Int32, INTTYPE ) )
536 sal_Int32 nValue(0);
537 if ( !( _value >>= nValue ) )
538 mysqlc_sdbc_driver::throwInvalidArgumentException( "OPreparedStatement::setObjectWithInfo", _rxParam );
539 (_rxParam.get()->*_Setter)( _parameterIndex, static_cast<INTTYPE>(nValue) );
543 void SAL_CALL OPreparedStatement::setObjectWithInfo(sal_Int32 _parameterIndex, const Any& _value, sal_Int32 _targetSqlType, sal_Int32 /* scale */)
544 throw(SQLException, RuntimeException, std::exception)
546 OSL_TRACE("OPreparedStatement::setObjectWithInfo");
547 checkDisposed(OPreparedStatement::rBHelper.bDisposed);
548 MutexGuard aGuard(m_aMutex);
549 checkParameterIndex( _parameterIndex );
551 if ( !_value.hasValue() )
553 setNull( _parameterIndex, _targetSqlType );
554 return;
557 switch ( _targetSqlType )
559 case DataType::DECIMAL:
560 case DataType::NUMERIC:
562 double nValue(0);
563 if ( _value >>= nValue )
565 setDouble( _parameterIndex, nValue );
566 break;
569 // run through
571 case DataType::CHAR:
572 case DataType::VARCHAR:
573 case DataType::LONGVARCHAR:
574 impl_setObject( this, _parameterIndex, _value, &XParameters::setString, true );
575 break;
577 case DataType::BIGINT:
579 sal_Int64 nValue = 0;
580 if ( !( _value >>= nValue ) )
581 mysqlc_sdbc_driver::throwInvalidArgumentException( "OPreparedStatement::setObjectWithInfo", *this );
582 setLong( _parameterIndex, nValue );
584 break;
586 case DataType::FLOAT:
587 case DataType::REAL:
589 float nValue = 0;
590 if ( _value >>= nValue )
592 setFloat(_parameterIndex,nValue);
593 break;
596 // run through if we couldn't set a float value
598 case DataType::DOUBLE:
600 double nValue(0);
601 if ( !( _value >>= nValue ) )
602 mysqlc_sdbc_driver::throwInvalidArgumentException( "OPreparedStatement::setObjectWithInfo", *this );
603 setDouble( _parameterIndex, nValue );
605 break;
607 case DataType::DATE:
608 impl_setObject( this, _parameterIndex, _value, &XParameters::setDate, true );
609 break;
611 case DataType::TIME:
612 impl_setObject( this, _parameterIndex, _value, &XParameters::setTime, true );
613 break;
615 case DataType::TIMESTAMP:
616 impl_setObject( this, _parameterIndex, _value, &XParameters::setTimestamp, true );
617 break;
619 case DataType::BINARY:
620 case DataType::VARBINARY:
621 case DataType::LONGVARBINARY:
623 if ( impl_setObject( this, _parameterIndex, _value, &XParameters::setBytes, false )
624 || impl_setObject( this, _parameterIndex, _value, &XParameters::setBlob, false )
625 || impl_setObject( this, _parameterIndex, _value, &XParameters::setClob, false )
627 break;
629 Reference< ::com::sun::star::io::XInputStream > xBinStream;
630 if ( _value >>= xBinStream )
632 setBinaryStream( _parameterIndex, xBinStream, xBinStream->available() );
633 break;
636 mysqlc_sdbc_driver::throwInvalidArgumentException( "OPreparedStatement::setObjectWithInfo", *this );
638 break;
640 case DataType::BIT:
641 case DataType::BOOLEAN:
643 bool bValue( false );
644 if ( _value >>= bValue )
646 setBoolean( _parameterIndex, bValue );
647 break;
649 sal_Int32 nValue( 0 );
650 if ( _value >>= nValue )
652 setBoolean( _parameterIndex, ( nValue != 0 ) );
653 break;
655 mysqlc_sdbc_driver::throwInvalidArgumentException( "OPreparedStatement::setObjectWithInfo", *this );
657 break;
659 case DataType::TINYINT:
660 impl_setObject( this, _parameterIndex, _value, &XParameters::setByte );
661 break;
663 case DataType::SMALLINT:
664 impl_setObject( this, _parameterIndex, _value, &XParameters::setShort );
665 break;
667 case DataType::INTEGER:
668 impl_setObject( this, _parameterIndex, _value, &XParameters::setInt );
669 break;
671 default:
672 mysqlc_sdbc_driver::throwInvalidArgumentException( "OPreparedStatement::setObjectWithInfo", *this );
673 break;
677 void SAL_CALL OPreparedStatement::setObjectNull(sal_Int32 parameter, sal_Int32 /* sqlType */, const rtl::OUString& /* typeName */)
678 throw(SQLException, RuntimeException, std::exception)
680 OSL_TRACE("OPreparedStatement::setObjectNull");
681 MutexGuard aGuard(m_aMutex);
682 checkDisposed(OPreparedStatement::rBHelper.bDisposed);
683 checkParameterIndex(parameter);
685 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setObjectNull", *this);
688 void SAL_CALL OPreparedStatement::setObject(sal_Int32 parameter, const Any& /* x */)
689 throw(SQLException, RuntimeException, std::exception)
691 OSL_TRACE("OPreparedStatement::setObject");
692 MutexGuard aGuard(m_aMutex);
693 checkDisposed(OPreparedStatement::rBHelper.bDisposed);
694 checkParameterIndex(parameter);
696 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setObject", *this);
699 void SAL_CALL OPreparedStatement::setShort(sal_Int32 parameter, sal_Int16 x)
700 throw(SQLException, RuntimeException, std::exception)
702 OSL_TRACE("OPreparedStatement::setShort");
703 MutexGuard aGuard(m_aMutex);
704 checkDisposed(OPreparedStatement::rBHelper.bDisposed);
705 checkParameterIndex(parameter);
707 try {
708 static_cast<sql::PreparedStatement *>(cppStatement)->setInt(parameter, x);
709 } catch (const sql::MethodNotImplementedException &) {
710 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setShort", *this);
711 } catch (const sql::SQLException &e) {
712 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_pConnection->getConnectionEncoding());
716 void SAL_CALL OPreparedStatement::setBytes(sal_Int32 parameter, const Sequence< sal_Int8 >& x)
717 throw(SQLException, RuntimeException, std::exception)
719 OSL_TRACE("OPreparedStatement::setBytes");
720 MutexGuard aGuard(m_aMutex);
721 checkDisposed(OPreparedStatement::rBHelper.bDisposed);
722 checkParameterIndex(parameter);
724 std::string blobby(reinterpret_cast<char const *>(x.getConstArray()), x.getLength());
725 try {
726 static_cast<sql::PreparedStatement *>(cppStatement)->setString(parameter, blobby);
727 } catch (const sql::MethodNotImplementedException &) {
728 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setBytes", *this);
729 } catch (const sql::SQLException &e) {
730 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_pConnection->getConnectionEncoding());
734 void SAL_CALL OPreparedStatement::setCharacterStream(sal_Int32 parameter,
735 const Reference< XInputStream >& /* x */,
736 sal_Int32 /* length */)
737 throw(SQLException, RuntimeException, std::exception)
739 OSL_TRACE("OPreparedStatement::setCharacterStream");
740 MutexGuard aGuard(m_aMutex);
741 checkDisposed(OPreparedStatement::rBHelper.bDisposed);
742 checkParameterIndex(parameter);
744 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setCharacterStream", *this);
747 void SAL_CALL OPreparedStatement::setBinaryStream(sal_Int32 parameter,
748 const Reference< XInputStream >& /* x */,
749 sal_Int32 /* length */)
750 throw(SQLException, RuntimeException, std::exception)
752 OSL_TRACE("OPreparedStatement::setBinaryStream");
753 MutexGuard aGuard(m_aMutex);
754 checkDisposed(OPreparedStatement::rBHelper.bDisposed);
755 checkParameterIndex(parameter);
757 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setBinaryStream", *this);
760 void SAL_CALL OPreparedStatement::clearParameters()
761 throw(SQLException, RuntimeException, std::exception)
763 OSL_TRACE("OPreparedStatement::clearParameters");
764 MutexGuard aGuard(m_aMutex);
765 checkDisposed(OPreparedStatement::rBHelper.bDisposed);
767 try {
768 static_cast<sql::PreparedStatement *>(cppStatement)->clearParameters();
769 } catch (const sql::MethodNotImplementedException &) {
770 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::clearParameters", *this);
771 } catch (const sql::SQLException &e) {
772 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_pConnection->getConnectionEncoding());
776 void SAL_CALL OPreparedStatement::clearBatch()
777 throw(SQLException, RuntimeException, std::exception)
779 OSL_TRACE("OPreparedStatement::clearBatch");
780 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::clearBatch", *this);
783 void SAL_CALL OPreparedStatement::addBatch()
784 throw(SQLException, RuntimeException, std::exception)
786 OSL_TRACE("OPreparedStatement::addBatch");
787 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::addBatch", *this);
790 Sequence< sal_Int32 > SAL_CALL OPreparedStatement::executeBatch()
791 throw(SQLException, RuntimeException, std::exception)
793 OSL_TRACE("OPreparedStatement::executeBatch");
794 Sequence< sal_Int32 > aRet= Sequence< sal_Int32 > ();
795 return aRet;
798 void OPreparedStatement::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any& rValue)
799 throw(Exception, std::exception)
801 OSL_TRACE("OPreparedStatement::setFastPropertyValue_NoBroadcast");
802 switch(nHandle)
804 case PROPERTY_ID_RESULTSETCONCURRENCY:
805 break;
806 case PROPERTY_ID_RESULTSETTYPE:
807 break;
808 case PROPERTY_ID_FETCHDIRECTION:
809 break;
810 case PROPERTY_ID_USEBOOKMARKS:
811 break;
812 default:
813 /* XXX: Recursion ?? */
814 OPreparedStatement::setFastPropertyValue_NoBroadcast(nHandle,rValue);
818 void OPreparedStatement::checkParameterIndex(sal_Int32 column)
820 OSL_TRACE("OPreparedStatement::checkColumnIndex");
821 if (column < 1 || column > (sal_Int32) m_paramCount) {
822 rtl::OUString buf( "Parameter index out of range" );
823 throw SQLException(buf, *this, rtl::OUString(), 1, Any ());
829 * Local variables:
830 * tab-width: 4
831 * c-basic-offset: 4
832 * End:
833 * vim600: noet sw=4 ts=4 fdm=marker
834 * vim<600: noet sw=4 ts=4
837 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */