bump product version to 4.1.6.2
[LibreOffice.git] / mysqlc / source / mysqlc_preparedstatement.cxx
blob31c0f8240ab3483b1fcecd643d43edf4c53b8dd6
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 /* {{{ my_i_to_a() -I- */
55 static inline char * my_i_to_a(char * buf, size_t buf_size, int a)
57 snprintf(buf, buf_size, "%d", a);
58 return buf;
60 /* }}} */
63 IMPLEMENT_SERVICE_INFO(OPreparedStatement,"com.sun.star.sdbcx.mysqlc.PreparedStatement","com.sun.star.sdbc.PreparedStatement");
66 /* {{{ OPreparedStatement::OPreparedStatement() -I- */
67 OPreparedStatement::OPreparedStatement(OConnection* _pConnection, sql::PreparedStatement * _cppPrepStmt)
68 :OCommonStatement(_pConnection, _cppPrepStmt)
70 OSL_TRACE("OPreparedStatement::OPreparedStatement");
71 m_pConnection = _pConnection;
72 m_pConnection->acquire();
74 try {
75 m_paramCount = ((sql::PreparedStatement *)cppStatement)->getParameterMetaData()->getParameterCount();
76 } catch (const sql::SQLException &e) {
77 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_pConnection->getConnectionEncoding());
80 /* }}} */
83 /* {{{ OPreparedStatement::~OPreparedStatement() -I- */
84 OPreparedStatement::~OPreparedStatement()
86 OSL_TRACE("OPreparedStatement::~OPreparedStatement");
88 /* }}} */
91 /* {{{ OPreparedStatement::acquire() -I- */
92 void SAL_CALL OPreparedStatement::acquire()
93 throw()
95 OSL_TRACE("OPreparedStatement::acquire");
96 OCommonStatement::acquire();
98 /* }}} */
101 /* {{{ OPreparedStatement::release() -I- */
102 void SAL_CALL OPreparedStatement::release()
103 throw()
105 OSL_TRACE("OPreparedStatement::release");
106 OCommonStatement::release();
108 /* }}} */
111 /* {{{ OPreparedStatement::queryInterface() -I- */
112 Any SAL_CALL OPreparedStatement::queryInterface(const Type & rType)
113 throw(RuntimeException)
115 OSL_TRACE("OPreparedStatement::queryInterface");
116 Any aRet = OCommonStatement::queryInterface(rType);
117 if (!aRet.hasValue()) {
118 aRet = OPreparedStatement_BASE::queryInterface(rType);
120 return (aRet);
122 /* }}} */
125 /* {{{ OPreparedStatement::getPropertySetInfo() -I- */
126 Sequence< Type > SAL_CALL OPreparedStatement::getTypes()
127 throw(RuntimeException)
129 OSL_TRACE("OPreparedStatement::getTypes");
130 return concatSequences(OPreparedStatement_BASE::getTypes(), OCommonStatement::getTypes());
132 /* }}} */
135 /* {{{ OPreparedStatement::getMetaData() -I- */
136 Reference< XResultSetMetaData > SAL_CALL OPreparedStatement::getMetaData()
137 throw(SQLException, RuntimeException)
139 OSL_TRACE("OPreparedStatement::getMetaData");
140 MutexGuard aGuard(m_aMutex);
141 checkDisposed(OPreparedStatement::rBHelper.bDisposed);
143 try {
144 if (!m_xMetaData.is()) {
145 m_xMetaData = new OResultSetMetaData(
146 ((sql::PreparedStatement *)cppStatement)->getMetaData(),
147 getOwnConnection()->getConnectionEncoding()
150 } catch (const sql::MethodNotImplementedException &) {
151 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::getMetaData", *this);
152 } catch (const sql::SQLException &e) {
153 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_pConnection->getConnectionEncoding());
155 return m_xMetaData;
157 /* }}} */
160 /* {{{ OPreparedStatement::close() -I- */
161 void SAL_CALL OPreparedStatement::close()
162 throw(SQLException, RuntimeException)
164 OSL_TRACE("OPreparedStatement::close");
166 MutexGuard aGuard(m_aMutex);
167 checkDisposed(OPreparedStatement::rBHelper.bDisposed);
169 try {
170 clearWarnings();
171 clearParameters();
172 OCommonStatement::close();
173 } catch (const SQLException &) {
174 // If we get an error, ignore
177 // Remove this Statement object from the Connection object's
178 // list
180 /* }}} */
183 /* {{{ OPreparedStatement::execute() -I- */
184 sal_Bool SAL_CALL OPreparedStatement::execute()
185 throw(SQLException, RuntimeException)
187 OSL_TRACE("OPreparedStatement::execute");
188 MutexGuard aGuard(m_aMutex);
189 checkDisposed(OPreparedStatement::rBHelper.bDisposed);
191 sal_Bool success = sal_False;
192 try {
193 success = ((sql::PreparedStatement *)cppStatement)->execute()? sal_True:sal_False;
194 } catch (const sql::SQLException &e) {
195 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_pConnection->getConnectionEncoding());
197 return success;
199 /* }}} */
202 /* {{{ OPreparedStatement::executeUpdate() -I- */
203 sal_Int32 SAL_CALL OPreparedStatement::executeUpdate()
204 throw(SQLException, RuntimeException)
206 OSL_TRACE("OPreparedStatement::executeUpdate");
207 MutexGuard aGuard(m_aMutex);
208 checkDisposed(OPreparedStatement::rBHelper.bDisposed);
210 sal_Int32 affectedRows = 0;
211 try {
212 affectedRows = ((sql::PreparedStatement *)cppStatement)->executeUpdate();
213 } catch (const sql::SQLException &e) {
214 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_pConnection->getConnectionEncoding());
216 return affectedRows;
218 /* }}} */
221 /* {{{ OPreparedStatement::getPropertySetInfo() -I- */
222 void SAL_CALL OPreparedStatement::setString(sal_Int32 parameter, const OUString& x)
223 throw(SQLException, RuntimeException)
225 OSL_TRACE("OPreparedStatement::setString");
226 MutexGuard aGuard(m_aMutex);
227 checkDisposed(OPreparedStatement::rBHelper.bDisposed);
228 checkParameterIndex(parameter);
230 try {
231 std::string stringie(OUStringToOString(x, m_pConnection->getConnectionEncoding()).getStr());
232 ((sql::PreparedStatement *)cppStatement)->setString(parameter, stringie);
233 } catch (const sql::MethodNotImplementedException &) {
234 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::clearParameters", *this);
235 } catch (const sql::SQLException &e) {
236 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_pConnection->getConnectionEncoding());
239 /* }}} */
242 /* {{{ OPreparedStatement::getConnection() -I- */
243 Reference< XConnection > SAL_CALL OPreparedStatement::getConnection()
244 throw(SQLException, RuntimeException)
246 OSL_TRACE("OPreparedStatement::getConnection");
247 MutexGuard aGuard(m_aMutex);
248 checkDisposed(OPreparedStatement::rBHelper.bDisposed);
250 return (Reference< XConnection >)m_pConnection;
252 /* }}} */
254 Reference< XResultSet > SAL_CALL OPreparedStatement::executeQuery(const OUString& sql)
255 throw(SQLException, RuntimeException)
257 return OCommonStatement::executeQuery( sql );
260 sal_Int32 SAL_CALL OPreparedStatement::executeUpdate(const OUString& sql)
261 throw(SQLException, RuntimeException)
263 return OCommonStatement::executeUpdate( sql );
266 sal_Bool SAL_CALL OPreparedStatement::execute( const OUString& sql )
267 throw(SQLException, RuntimeException)
269 return OCommonStatement::execute( sql );
272 /* {{{ OPreparedStatement::executeQuery() -I- */
273 Reference< XResultSet > SAL_CALL OPreparedStatement::executeQuery()
274 throw(SQLException, RuntimeException)
276 OSL_TRACE("OPreparedStatement::executeQuery");
277 MutexGuard aGuard(m_aMutex);
278 checkDisposed(OPreparedStatement::rBHelper.bDisposed);
280 Reference< XResultSet > xResultSet;
281 try {
282 sql::ResultSet * res = ((sql::PreparedStatement *)cppStatement)->executeQuery();
283 xResultSet = new OResultSet(this, res, getOwnConnection()->getConnectionEncoding());
284 } catch (const sql::SQLException &e) {
285 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_pConnection->getConnectionEncoding());
287 return xResultSet;
289 /* }}} */
292 /* {{{ OPreparedStatement::setBoolean() -I- */
293 void SAL_CALL OPreparedStatement::setBoolean(sal_Int32 parameter, sal_Bool x)
294 throw(SQLException, RuntimeException)
296 OSL_TRACE("OPreparedStatement::setBoolean");
297 MutexGuard aGuard(m_aMutex);
298 checkDisposed(OPreparedStatement::rBHelper.bDisposed);
299 checkParameterIndex(parameter);
301 try {
302 ((sql::PreparedStatement *)cppStatement)->setBoolean(parameter, x);
303 } catch (const sql::MethodNotImplementedException &) {
304 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setBoolean", *this);
305 } catch (const sql::SQLException &e) {
306 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_pConnection->getConnectionEncoding());
309 /* }}} */
312 /* {{{ OPreparedStatement::setByte() -I- */
313 void SAL_CALL OPreparedStatement::setByte(sal_Int32 parameter, sal_Int8 x)
314 throw(SQLException, RuntimeException)
316 OSL_TRACE("OPreparedStatement::setByte");
317 MutexGuard aGuard(m_aMutex);
318 checkDisposed(OPreparedStatement::rBHelper.bDisposed);
319 checkParameterIndex(parameter);
321 try {
322 ((sql::PreparedStatement *)cppStatement)->setInt(parameter, x);
323 } catch (const sql::MethodNotImplementedException &) {
324 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setByte", *this);
325 } catch (const sql::SQLException &e) {
326 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_pConnection->getConnectionEncoding());
329 /* }}} */
332 /* {{{ OPreparedStatement::setDate() -I- */
333 void SAL_CALL OPreparedStatement::setDate(sal_Int32 parameter, const Date& aData)
334 throw(SQLException, RuntimeException)
336 OSL_TRACE("OPreparedStatement::setDate");
337 MutexGuard aGuard(m_aMutex);
338 checkDisposed(OPreparedStatement::rBHelper.bDisposed);
339 checkParameterIndex(parameter);
341 std::string dateStr;
342 char buf[20];
343 dateStr.append(my_i_to_a(buf, sizeof(buf)-1, aData.Year));
344 dateStr.append("-", 1);
345 dateStr.append(my_i_to_a(buf, sizeof(buf)-1, aData.Month));
346 dateStr.append("-", 1);
347 dateStr.append(my_i_to_a(buf, sizeof(buf)-1, aData.Day));
349 try {
350 ((sql::PreparedStatement *)cppStatement)->setDateTime(parameter, dateStr);
351 } catch (const sql::MethodNotImplementedException &) {
352 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setDate", *this);
353 } catch (const sql::SQLException &e) {
354 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_pConnection->getConnectionEncoding());
357 /* }}} */
360 /* {{{ OPreparedStatement::setTime() -I- */
361 void SAL_CALL OPreparedStatement::setTime(sal_Int32 parameter, const Time& aVal)
362 throw(SQLException, RuntimeException)
364 OSL_TRACE("OPreparedStatement::setTime");
365 MutexGuard aGuard(m_aMutex);
366 checkDisposed(OPreparedStatement::rBHelper.bDisposed);
367 checkParameterIndex(parameter);
369 std::string timeStr;
370 char buf[20];
371 timeStr.append(my_i_to_a(buf, sizeof(buf)-1, aVal.Hours));
372 timeStr.append(":", 1);
373 timeStr.append(my_i_to_a(buf, sizeof(buf)-1, aVal.Minutes));
374 timeStr.append(":", 1);
375 timeStr.append(my_i_to_a(buf, sizeof(buf)-1, aVal.Seconds));
377 try {
378 ((sql::PreparedStatement *)cppStatement)->setDateTime(parameter, timeStr);
379 } catch (const sql::MethodNotImplementedException &) {
380 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setTime", *this);
381 } catch (const sql::SQLException &e) {
382 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_pConnection->getConnectionEncoding());
385 /* }}} */
388 /* {{{ OPreparedStatement::setTimestamp() -I- */
389 void SAL_CALL OPreparedStatement::setTimestamp(sal_Int32 parameter, const DateTime& aVal)
390 throw(SQLException, RuntimeException)
392 OSL_TRACE("OPreparedStatement::setTimestamp");
393 MutexGuard aGuard(m_aMutex);
394 checkDisposed(OPreparedStatement::rBHelper.bDisposed);
395 checkParameterIndex(parameter);
397 std::string timeStr;
398 char buf[20];
399 timeStr.append(my_i_to_a(buf, sizeof(buf)-1, aVal.Year));
400 timeStr.append("-", 1);
401 timeStr.append(my_i_to_a(buf, sizeof(buf)-1, aVal.Month));
402 timeStr.append("-", 1);
403 timeStr.append(my_i_to_a(buf, sizeof(buf)-1, aVal.Day));
405 timeStr.append(" ", 1);
407 timeStr.append(my_i_to_a(buf, sizeof(buf)-1, aVal.Hours));
408 timeStr.append(":", 1);
409 timeStr.append(my_i_to_a(buf, sizeof(buf)-1, aVal.Minutes));
410 timeStr.append(":", 1);
411 timeStr.append(my_i_to_a(buf, sizeof(buf)-1, aVal.Seconds));
413 try {
414 ((sql::PreparedStatement *)cppStatement)->setDateTime(parameter, timeStr);
415 } catch (const sql::MethodNotImplementedException &) {
416 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setTimestamp", *this);
417 } catch (const sql::SQLException &e) {
418 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_pConnection->getConnectionEncoding());
421 /* }}} */
424 /* {{{ OPreparedStatement::setDouble() -I- */
425 void SAL_CALL OPreparedStatement::setDouble(sal_Int32 parameter, double x)
426 throw(SQLException, RuntimeException)
428 OSL_TRACE("OPreparedStatement::setDouble");
429 MutexGuard aGuard(m_aMutex);
430 checkDisposed(OPreparedStatement::rBHelper.bDisposed);
431 checkParameterIndex(parameter);
433 try {
434 ((sql::PreparedStatement *)cppStatement)->setDouble(parameter, x);
435 } catch (const sql::MethodNotImplementedException &) {
436 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setDouble", *this);
437 } catch (const sql::SQLException &e) {
438 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_pConnection->getConnectionEncoding());
441 /* }}} */
444 /* {{{ OPreparedStatement::setFloat() -I- */
445 void SAL_CALL OPreparedStatement::setFloat(sal_Int32 parameter, float x)
446 throw(SQLException, RuntimeException)
448 OSL_TRACE("OPreparedStatement::setFloat");
449 MutexGuard aGuard(m_aMutex);
450 checkDisposed(OPreparedStatement::rBHelper.bDisposed);
451 checkParameterIndex(parameter);
453 try {
454 ((sql::PreparedStatement *)cppStatement)->setDouble(parameter, x);
455 } catch (const sql::MethodNotImplementedException &) {
456 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setFloat", *this);
457 } catch (const sql::SQLException &e) {
458 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_pConnection->getConnectionEncoding());
461 /* }}} */
464 /* {{{ OPreparedStatement::setInt() -I- */
465 void SAL_CALL OPreparedStatement::setInt(sal_Int32 parameter, sal_Int32 x)
466 throw(SQLException, RuntimeException)
468 OSL_TRACE("OPreparedStatement::setInt");
469 MutexGuard aGuard(m_aMutex);
470 checkDisposed(OPreparedStatement::rBHelper.bDisposed);
471 checkParameterIndex(parameter);
473 try {
474 ((sql::PreparedStatement *)cppStatement)->setInt(parameter, x);
475 } catch (const sql::MethodNotImplementedException &) {
476 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setInt", *this);
477 } catch (const sql::SQLException &e) {
478 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_pConnection->getConnectionEncoding());
481 /* }}} */
484 /* {{{ OPreparedStatement::setLong() -I- */
485 void SAL_CALL OPreparedStatement::setLong(sal_Int32 parameter, sal_Int64 aVal)
486 throw(SQLException, RuntimeException)
488 OSL_TRACE("OPreparedStatement::setLong");
489 MutexGuard aGuard(m_aMutex);
490 checkDisposed(OPreparedStatement::rBHelper.bDisposed);
491 checkParameterIndex(parameter);
493 try {
494 ((sql::PreparedStatement *)cppStatement)->setInt64(parameter, aVal);
495 } catch (const sql::MethodNotImplementedException &) {
496 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setLong", *this);
497 } catch (const sql::SQLException &e) {
498 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_pConnection->getConnectionEncoding());
501 /* }}} */
504 /* {{{ OPreparedStatement::setNull() -I- */
505 void SAL_CALL OPreparedStatement::setNull(sal_Int32 parameter, sal_Int32 sqlType)
506 throw(SQLException, RuntimeException)
508 OSL_TRACE("OPreparedStatement::setNull");
509 MutexGuard aGuard(m_aMutex);
510 checkDisposed(OPreparedStatement::rBHelper.bDisposed);
511 checkParameterIndex(parameter);
513 try {
514 ((sql::PreparedStatement *)cppStatement)->setNull(parameter, sqlType);
515 } catch (const sql::MethodNotImplementedException &) {
516 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setNull", *this);
517 } catch (const sql::SQLException &e) {
518 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_pConnection->getConnectionEncoding());
521 /* }}} */
524 /* {{{ OPreparedStatement::setClob() -U- */
525 void SAL_CALL OPreparedStatement::setClob(sal_Int32 parameter, const Reference< XClob >& /* x */)
526 throw(SQLException, RuntimeException)
528 OSL_TRACE("OPreparedStatement::setClob");
529 MutexGuard aGuard(m_aMutex);
530 checkDisposed(OPreparedStatement::rBHelper.bDisposed);
531 checkParameterIndex(parameter);
533 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setClob", *this);
535 /* }}} */
538 /* {{{ OPreparedStatement::setBlob() -U- */
539 void SAL_CALL OPreparedStatement::setBlob(sal_Int32 parameter, const Reference< XBlob >& /* x */)
540 throw(SQLException, RuntimeException)
542 OSL_TRACE("OPreparedStatement::setBlob");
543 MutexGuard aGuard(m_aMutex);
544 checkDisposed(OPreparedStatement::rBHelper.bDisposed);
545 checkParameterIndex(parameter);
547 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setBlob", *this);
549 /* }}} */
552 /* {{{ OPreparedStatement::setArray() -U- */
553 void SAL_CALL OPreparedStatement::setArray(sal_Int32 parameter, const Reference< XArray >& /* x */)
554 throw(SQLException, RuntimeException)
556 OSL_TRACE("OPreparedStatement::setArray");
557 MutexGuard aGuard(m_aMutex);
558 checkDisposed(OPreparedStatement::rBHelper.bDisposed);
559 checkParameterIndex(parameter);
561 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setArray", *this);
563 /* }}} */
566 /* {{{ OPreparedStatement::setRef() -U- */
567 void SAL_CALL OPreparedStatement::setRef(sal_Int32 parameter, const Reference< XRef >& /* x */)
568 throw(SQLException, RuntimeException)
570 OSL_TRACE("OPreparedStatement::setRef");
571 MutexGuard aGuard(m_aMutex);
572 checkDisposed(OPreparedStatement::rBHelper.bDisposed);
573 checkParameterIndex(parameter);
575 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setRef", *this);
577 /* }}} */
579 namespace
581 template < class COMPLEXTYPE >
582 bool impl_setObject( const Reference< XParameters >& _rxParam, sal_Int32 _parameterIndex, const Any& _value,
583 void ( SAL_CALL XParameters::*_Setter )( sal_Int32, const COMPLEXTYPE& ), bool _throwIfNotExtractable )
585 COMPLEXTYPE aValue;
586 if ( _value >>= aValue )
588 (_rxParam.get()->*_Setter)( _parameterIndex, aValue );
589 return true;
592 if ( _throwIfNotExtractable )
593 mysqlc_sdbc_driver::throwInvalidArgumentException( "OPreparedStatement::setObjectWithInfo", _rxParam );
594 return false;
597 template < class INTTYPE >
598 void impl_setObject( const Reference< XParameters >& _rxParam, sal_Int32 _parameterIndex, const Any& _value,
599 void ( SAL_CALL XParameters::*_Setter )( sal_Int32, INTTYPE ) )
601 sal_Int32 nValue(0);
602 if ( !( _value >>= nValue ) )
603 mysqlc_sdbc_driver::throwInvalidArgumentException( "OPreparedStatement::setObjectWithInfo", _rxParam );
604 (_rxParam.get()->*_Setter)( _parameterIndex, (INTTYPE)nValue );
608 /* {{{ OPreparedStatement::setObjectWithInfo() -U- */
609 void SAL_CALL OPreparedStatement::setObjectWithInfo(sal_Int32 _parameterIndex, const Any& _value, sal_Int32 _targetSqlType, sal_Int32 /* scale */)
610 throw(SQLException, RuntimeException)
612 OSL_TRACE("OPreparedStatement::setObjectWithInfo");
613 checkDisposed(OPreparedStatement::rBHelper.bDisposed);
614 MutexGuard aGuard(m_aMutex);
615 checkParameterIndex( _parameterIndex );
617 if ( !_value.hasValue() )
619 setNull( _parameterIndex, _targetSqlType );
620 return;
623 switch ( _targetSqlType )
625 case DataType::DECIMAL:
626 case DataType::NUMERIC:
628 double nValue(0);
629 if ( _value >>= nValue )
631 setDouble( _parameterIndex, nValue );
632 break;
635 // run through
637 case DataType::CHAR:
638 case DataType::VARCHAR:
639 case DataType::LONGVARCHAR:
640 impl_setObject( this, _parameterIndex, _value, &XParameters::setString, true );
641 break;
643 case DataType::BIGINT:
645 sal_Int64 nValue = 0;
646 if ( !( _value >>= nValue ) )
647 mysqlc_sdbc_driver::throwInvalidArgumentException( "OPreparedStatement::setObjectWithInfo", *this );
648 setLong( _parameterIndex, nValue );
650 break;
652 case DataType::FLOAT:
653 case DataType::REAL:
655 float nValue = 0;
656 if ( _value >>= nValue )
658 setFloat(_parameterIndex,nValue);
659 break;
662 // run through if we couldn't set a float value
664 case DataType::DOUBLE:
666 double nValue(0);
667 if ( !( _value >>= nValue ) )
668 mysqlc_sdbc_driver::throwInvalidArgumentException( "OPreparedStatement::setObjectWithInfo", *this );
669 setDouble( _parameterIndex, nValue );
671 break;
673 case DataType::DATE:
674 impl_setObject( this, _parameterIndex, _value, &XParameters::setDate, true );
675 break;
677 case DataType::TIME:
678 impl_setObject( this, _parameterIndex, _value, &XParameters::setTime, true );
679 break;
681 case DataType::TIMESTAMP:
682 impl_setObject( this, _parameterIndex, _value, &XParameters::setTimestamp, true );
683 break;
685 case DataType::BINARY:
686 case DataType::VARBINARY:
687 case DataType::LONGVARBINARY:
689 if ( impl_setObject( this, _parameterIndex, _value, &XParameters::setBytes, false )
690 || impl_setObject( this, _parameterIndex, _value, &XParameters::setBlob, false )
691 || impl_setObject( this, _parameterIndex, _value, &XParameters::setClob, false )
693 break;
695 Reference< ::com::sun::star::io::XInputStream > xBinStream;
696 if ( _value >>= xBinStream )
698 setBinaryStream( _parameterIndex, xBinStream, xBinStream->available() );
699 break;
702 mysqlc_sdbc_driver::throwInvalidArgumentException( "OPreparedStatement::setObjectWithInfo", *this );
704 break;
706 case DataType::BIT:
707 case DataType::BOOLEAN:
709 bool bValue( false );
710 if ( _value >>= bValue )
712 setBoolean( _parameterIndex, bValue );
713 break;
715 sal_Int32 nValue( 0 );
716 if ( _value >>= nValue )
718 setBoolean( _parameterIndex, ( nValue != 0 ) );
719 break;
721 mysqlc_sdbc_driver::throwInvalidArgumentException( "OPreparedStatement::setObjectWithInfo", *this );
723 break;
725 case DataType::TINYINT:
726 impl_setObject( this, _parameterIndex, _value, &XParameters::setByte );
727 break;
729 case DataType::SMALLINT:
730 impl_setObject( this, _parameterIndex, _value, &XParameters::setShort );
731 break;
733 case DataType::INTEGER:
734 impl_setObject( this, _parameterIndex, _value, &XParameters::setInt );
735 break;
737 default:
738 mysqlc_sdbc_driver::throwInvalidArgumentException( "OPreparedStatement::setObjectWithInfo", *this );
739 break;
742 /* }}} */
745 /* {{{ OPreparedStatement::setObjectNull() -U- */
746 void SAL_CALL OPreparedStatement::setObjectNull(sal_Int32 parameter, sal_Int32 /* sqlType */, const OUString& /* typeName */)
747 throw(SQLException, RuntimeException)
749 OSL_TRACE("OPreparedStatement::setObjectNull");
750 MutexGuard aGuard(m_aMutex);
751 checkDisposed(OPreparedStatement::rBHelper.bDisposed);
752 checkParameterIndex(parameter);
754 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setObjectNull", *this);
756 /* }}} */
759 /* {{{ OPreparedStatement::setObject() -U- */
760 void SAL_CALL OPreparedStatement::setObject(sal_Int32 parameter, const Any& /* x */)
761 throw(SQLException, RuntimeException)
763 OSL_TRACE("OPreparedStatement::setObject");
764 MutexGuard aGuard(m_aMutex);
765 checkDisposed(OPreparedStatement::rBHelper.bDisposed);
766 checkParameterIndex(parameter);
768 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setObject", *this);
770 /* }}} */
773 /* {{{ OPreparedStatement::setShort() -I- */
774 void SAL_CALL OPreparedStatement::setShort(sal_Int32 parameter, sal_Int16 x)
775 throw(SQLException, RuntimeException)
777 OSL_TRACE("OPreparedStatement::setShort");
778 MutexGuard aGuard(m_aMutex);
779 checkDisposed(OPreparedStatement::rBHelper.bDisposed);
780 checkParameterIndex(parameter);
782 try {
783 ((sql::PreparedStatement *)cppStatement)->setInt(parameter, x);
784 } catch (const sql::MethodNotImplementedException &) {
785 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setShort", *this);
786 } catch (const sql::SQLException &e) {
787 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_pConnection->getConnectionEncoding());
790 /* }}} */
793 /* {{{ OPreparedStatement::setBytes() -I- */
794 void SAL_CALL OPreparedStatement::setBytes(sal_Int32 parameter, const Sequence< sal_Int8 >& x)
795 throw(SQLException, RuntimeException)
797 OSL_TRACE("OPreparedStatement::setBytes");
798 MutexGuard aGuard(m_aMutex);
799 checkDisposed(OPreparedStatement::rBHelper.bDisposed);
800 checkParameterIndex(parameter);
802 std::string blobby((char *)x.getConstArray(), x.getLength());
803 try {
804 ((sql::PreparedStatement *)cppStatement)->setString(parameter, blobby);
805 } catch (const sql::MethodNotImplementedException &) {
806 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setBytes", *this);
807 } catch (const sql::SQLException &e) {
808 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_pConnection->getConnectionEncoding());
811 /* }}} */
814 /* {{{ OPreparedStatement::setCharacterStream() -U- */
815 void SAL_CALL OPreparedStatement::setCharacterStream(sal_Int32 parameter,
816 const Reference< XInputStream >& /* x */,
817 sal_Int32 /* length */)
818 throw(SQLException, RuntimeException)
820 OSL_TRACE("OPreparedStatement::setCharacterStream");
821 MutexGuard aGuard(m_aMutex);
822 checkDisposed(OPreparedStatement::rBHelper.bDisposed);
823 checkParameterIndex(parameter);
825 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setCharacterStream", *this);
827 /* }}} */
830 /* {{{ OPreparedStatement::setBinaryStream() -U- */
831 void SAL_CALL OPreparedStatement::setBinaryStream(sal_Int32 parameter,
832 const Reference< XInputStream >& /* x */,
833 sal_Int32 /* length */)
834 throw(SQLException, RuntimeException)
836 OSL_TRACE("OPreparedStatement::setBinaryStream");
837 MutexGuard aGuard(m_aMutex);
838 checkDisposed(OPreparedStatement::rBHelper.bDisposed);
839 checkParameterIndex(parameter);
841 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setBinaryStream", *this);
843 /* }}} */
846 /* {{{ OPreparedStatement::clearParameters() -I- */
847 void SAL_CALL OPreparedStatement::clearParameters()
848 throw(SQLException, RuntimeException)
850 OSL_TRACE("OPreparedStatement::clearParameters");
851 MutexGuard aGuard(m_aMutex);
852 checkDisposed(OPreparedStatement::rBHelper.bDisposed);
854 try {
855 ((sql::PreparedStatement *)cppStatement)->clearParameters();
856 } catch (const sql::MethodNotImplementedException &) {
857 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::clearParameters", *this);
858 } catch (const sql::SQLException &e) {
859 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_pConnection->getConnectionEncoding());
862 /* }}} */
865 /* {{{ OPreparedStatement::clearBatch() -U- */
866 void SAL_CALL OPreparedStatement::clearBatch()
867 throw(SQLException, RuntimeException)
869 OSL_TRACE("OPreparedStatement::clearBatch");
870 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::clearBatch", *this);
872 /* }}} */
875 /* {{{ OPreparedStatement::addBatch() -U- */
876 void SAL_CALL OPreparedStatement::addBatch()
877 throw(SQLException, RuntimeException)
879 OSL_TRACE("OPreparedStatement::addBatch");
880 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::addBatch", *this);
882 /* }}} */
885 /* {{{ OPreparedStatement::executeBatch() -I- */
886 Sequence< sal_Int32 > SAL_CALL OPreparedStatement::executeBatch()
887 throw(SQLException, RuntimeException)
889 OSL_TRACE("OPreparedStatement::executeBatch");
890 Sequence< sal_Int32 > aRet= Sequence< sal_Int32 > ();
891 return aRet;
893 /* }}} */
896 /* {{{ OPreparedStatement::setFastPropertyValue_NoBroadcast() -I- */
897 void OPreparedStatement::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any& rValue)
898 throw(Exception)
900 OSL_TRACE("OPreparedStatement::setFastPropertyValue_NoBroadcast");
901 switch(nHandle)
903 case PROPERTY_ID_RESULTSETCONCURRENCY:
904 break;
905 case PROPERTY_ID_RESULTSETTYPE:
906 break;
907 case PROPERTY_ID_FETCHDIRECTION:
908 break;
909 case PROPERTY_ID_USEBOOKMARKS:
910 break;
911 default:
912 /* XXX: Recursion ?? */
913 OPreparedStatement::setFastPropertyValue_NoBroadcast(nHandle,rValue);
916 /* }}} */
919 /* {{{ OPreparedStatement::checkParameterIndex() -I- */
920 void OPreparedStatement::checkParameterIndex(sal_Int32 column)
922 OSL_TRACE("OPreparedStatement::checkColumnIndex");
923 if (column < 1 || column > (sal_Int32) m_paramCount) {
924 OUString buf( "Parameter index out of range" );
925 throw SQLException(buf, *this, OUString(), 1, Any ());
928 /* }}} */
932 * Local variables:
933 * tab-width: 4
934 * c-basic-offset: 4
935 * End:
936 * vim600: noet sw=4 ts=4 fdm=marker
937 * vim<600: noet sw=4 ts=4
940 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */