1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
38 using namespace connectivity::mysqlc
;
39 using namespace com::sun::star::uno
;
40 using namespace com::sun::star::lang
;
41 using namespace com::sun::star::beans
;
42 using namespace com::sun::star::sdbc
;
43 using namespace com::sun::star::container
;
44 using namespace com::sun::star::io
;
45 using namespace com::sun::star::util
;
46 using ::osl::MutexGuard
;
47 using mysqlc_sdbc_driver::getStringFromAny
;
50 /* {{{ my_i_to_a() -I- */
51 static inline char * my_i_to_a(char * buf
, size_t buf_size
, int a
)
53 snprintf(buf
, buf_size
, "%d", a
);
59 IMPLEMENT_SERVICE_INFO(OPreparedStatement
,"com.sun.star.sdbcx.mysqlc.PreparedStatement","com.sun.star.sdbc.PreparedStatement");
62 /* {{{ OPreparedStatement::OPreparedStatement() -I- */
63 OPreparedStatement::OPreparedStatement(OConnection
* _pConnection
, sql::PreparedStatement
* _cppPrepStmt
)
64 :OCommonStatement(_pConnection
, _cppPrepStmt
)
66 OSL_TRACE("OPreparedStatement::OPreparedStatement");
67 m_pConnection
= _pConnection
;
68 m_pConnection
->acquire();
71 m_paramCount
= ((sql::PreparedStatement
*)cppStatement
)->getParameterMetaData()->getParameterCount();
72 } catch (const sql::SQLException
&e
) {
73 mysqlc_sdbc_driver::translateAndThrow(e
, *this, m_pConnection
->getConnectionEncoding());
79 /* {{{ OPreparedStatement::~OPreparedStatement() -I- */
80 OPreparedStatement::~OPreparedStatement()
82 OSL_TRACE("OPreparedStatement::~OPreparedStatement");
87 /* {{{ OPreparedStatement::acquire() -I- */
88 void SAL_CALL
OPreparedStatement::acquire()
91 OSL_TRACE("OPreparedStatement::acquire");
92 OCommonStatement::acquire();
97 /* {{{ OPreparedStatement::release() -I- */
98 void SAL_CALL
OPreparedStatement::release()
101 OSL_TRACE("OPreparedStatement::release");
102 OCommonStatement::release();
107 /* {{{ OPreparedStatement::queryInterface() -I- */
108 Any SAL_CALL
OPreparedStatement::queryInterface(const Type
& rType
)
109 throw(RuntimeException
)
111 OSL_TRACE("OPreparedStatement::queryInterface");
112 Any aRet
= OCommonStatement::queryInterface(rType
);
113 if (!aRet
.hasValue()) {
114 aRet
= OPreparedStatement_BASE::queryInterface(rType
);
121 /* {{{ OPreparedStatement::getPropertySetInfo() -I- */
122 Sequence
< Type
> SAL_CALL
OPreparedStatement::getTypes()
123 throw(RuntimeException
)
125 OSL_TRACE("OPreparedStatement::getTypes");
126 return concatSequences(OPreparedStatement_BASE::getTypes(), OCommonStatement::getTypes());
131 /* {{{ OPreparedStatement::getMetaData() -I- */
132 Reference
< XResultSetMetaData
> SAL_CALL
OPreparedStatement::getMetaData()
133 throw(SQLException
, RuntimeException
)
135 OSL_TRACE("OPreparedStatement::getMetaData");
136 MutexGuard
aGuard(m_aMutex
);
137 checkDisposed(OPreparedStatement::rBHelper
.bDisposed
);
140 if (!m_xMetaData
.is()) {
141 m_xMetaData
= new OResultSetMetaData(
142 ((sql::PreparedStatement
*)cppStatement
)->getMetaData(),
143 getOwnConnection()->getConnectionEncoding()
146 } catch (const sql::MethodNotImplementedException
&) {
147 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::getMetaData", *this);
148 } catch (const sql::SQLException
&e
) {
149 mysqlc_sdbc_driver::translateAndThrow(e
, *this, m_pConnection
->getConnectionEncoding());
156 /* {{{ OPreparedStatement::close() -I- */
157 void SAL_CALL
OPreparedStatement::close()
158 throw(SQLException
, RuntimeException
)
160 OSL_TRACE("OPreparedStatement::close");
162 MutexGuard
aGuard(m_aMutex
);
163 checkDisposed(OPreparedStatement::rBHelper
.bDisposed
);
168 OCommonStatement::close();
169 } catch (const SQLException
&) {
170 // If we get an error, ignore
173 // Remove this Statement object from the Connection object's
179 /* {{{ OPreparedStatement::execute() -I- */
180 sal_Bool SAL_CALL
OPreparedStatement::execute()
181 throw(SQLException
, RuntimeException
)
183 OSL_TRACE("OPreparedStatement::execute");
184 MutexGuard
aGuard(m_aMutex
);
185 checkDisposed(OPreparedStatement::rBHelper
.bDisposed
);
187 sal_Bool success
= sal_False
;
189 success
= ((sql::PreparedStatement
*)cppStatement
)->execute()? sal_True
:sal_False
;
190 } catch (const sql::SQLException
&e
) {
191 mysqlc_sdbc_driver::translateAndThrow(e
, *this, m_pConnection
->getConnectionEncoding());
198 /* {{{ OPreparedStatement::executeUpdate() -I- */
199 sal_Int32 SAL_CALL
OPreparedStatement::executeUpdate()
200 throw(SQLException
, RuntimeException
)
202 OSL_TRACE("OPreparedStatement::executeUpdate");
203 MutexGuard
aGuard(m_aMutex
);
204 checkDisposed(OPreparedStatement::rBHelper
.bDisposed
);
206 sal_Int32 affectedRows
= sal_False
;
208 affectedRows
= ((sql::PreparedStatement
*)cppStatement
)->executeUpdate();
209 } catch (const sql::SQLException
&e
) {
210 mysqlc_sdbc_driver::translateAndThrow(e
, *this, m_pConnection
->getConnectionEncoding());
217 /* {{{ OPreparedStatement::getPropertySetInfo() -I- */
218 void SAL_CALL
OPreparedStatement::setString(sal_Int32 parameter
, const OUString
& x
)
219 throw(SQLException
, RuntimeException
)
221 OSL_TRACE("OPreparedStatement::setString");
222 MutexGuard
aGuard(m_aMutex
);
223 checkDisposed(OPreparedStatement::rBHelper
.bDisposed
);
224 checkParameterIndex(parameter
);
227 std::string
stringie(::rtl::OUStringToOString(x
, m_pConnection
->getConnectionEncoding()).getStr());
228 ((sql::PreparedStatement
*)cppStatement
)->setString(parameter
, stringie
);
229 } catch (const sql::MethodNotImplementedException
&) {
230 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::clearParameters", *this);
231 } catch (const sql::SQLException
&e
) {
232 mysqlc_sdbc_driver::translateAndThrow(e
, *this, m_pConnection
->getConnectionEncoding());
238 /* {{{ OPreparedStatement::getConnection() -I- */
239 Reference
< XConnection
> SAL_CALL
OPreparedStatement::getConnection()
240 throw(SQLException
, RuntimeException
)
242 OSL_TRACE("OPreparedStatement::getConnection");
243 MutexGuard
aGuard(m_aMutex
);
244 checkDisposed(OPreparedStatement::rBHelper
.bDisposed
);
246 return (Reference
< XConnection
>)m_pConnection
;
250 Reference
< XResultSet
> SAL_CALL
OPreparedStatement::executeQuery(const OUString
& sql
)
251 throw(SQLException
, RuntimeException
)
253 return OCommonStatement::executeQuery( sql
);
256 sal_Int32 SAL_CALL
OPreparedStatement::executeUpdate(const OUString
& sql
)
257 throw(SQLException
, RuntimeException
)
259 return OCommonStatement::executeUpdate( sql
);
262 sal_Bool SAL_CALL
OPreparedStatement::execute( const OUString
& sql
)
263 throw(SQLException
, RuntimeException
)
265 return OCommonStatement::execute( sql
);
268 /* {{{ OPreparedStatement::executeQuery() -I- */
269 Reference
< XResultSet
> SAL_CALL
OPreparedStatement::executeQuery()
270 throw(SQLException
, RuntimeException
)
272 OSL_TRACE("OPreparedStatement::executeQuery");
273 MutexGuard
aGuard(m_aMutex
);
274 checkDisposed(OPreparedStatement::rBHelper
.bDisposed
);
276 Reference
< XResultSet
> xResultSet
;
278 sql::ResultSet
* res
= ((sql::PreparedStatement
*)cppStatement
)->executeQuery();
279 xResultSet
= new OResultSet(this, res
, getOwnConnection()->getConnectionEncoding());
280 } catch (const sql::SQLException
&e
) {
281 mysqlc_sdbc_driver::translateAndThrow(e
, *this, m_pConnection
->getConnectionEncoding());
288 /* {{{ OPreparedStatement::setBoolean() -I- */
289 void SAL_CALL
OPreparedStatement::setBoolean(sal_Int32 parameter
, sal_Bool x
)
290 throw(SQLException
, RuntimeException
)
292 OSL_TRACE("OPreparedStatement::setBoolean");
293 MutexGuard
aGuard(m_aMutex
);
294 checkDisposed(OPreparedStatement::rBHelper
.bDisposed
);
295 checkParameterIndex(parameter
);
298 ((sql::PreparedStatement
*)cppStatement
)->setBoolean(parameter
, x
);
299 } catch (const sql::MethodNotImplementedException
&) {
300 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setBoolean", *this);
301 } catch (const sql::SQLException
&e
) {
302 mysqlc_sdbc_driver::translateAndThrow(e
, *this, m_pConnection
->getConnectionEncoding());
308 /* {{{ OPreparedStatement::setByte() -I- */
309 void SAL_CALL
OPreparedStatement::setByte(sal_Int32 parameter
, sal_Int8 x
)
310 throw(SQLException
, RuntimeException
)
312 OSL_TRACE("OPreparedStatement::setByte");
313 MutexGuard
aGuard(m_aMutex
);
314 checkDisposed(OPreparedStatement::rBHelper
.bDisposed
);
315 checkParameterIndex(parameter
);
318 ((sql::PreparedStatement
*)cppStatement
)->setInt(parameter
, x
);
319 } catch (const sql::MethodNotImplementedException
&) {
320 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setByte", *this);
321 } catch (const sql::SQLException
&e
) {
322 mysqlc_sdbc_driver::translateAndThrow(e
, *this, m_pConnection
->getConnectionEncoding());
328 /* {{{ OPreparedStatement::setDate() -I- */
329 void SAL_CALL
OPreparedStatement::setDate(sal_Int32 parameter
, const Date
& aData
)
330 throw(SQLException
, RuntimeException
)
332 OSL_TRACE("OPreparedStatement::setDate");
333 MutexGuard
aGuard(m_aMutex
);
334 checkDisposed(OPreparedStatement::rBHelper
.bDisposed
);
335 checkParameterIndex(parameter
);
339 dateStr
.append(my_i_to_a(buf
, sizeof(buf
)-1, aData
.Year
));
340 dateStr
.append("-", 1);
341 dateStr
.append(my_i_to_a(buf
, sizeof(buf
)-1, aData
.Month
));
342 dateStr
.append("-", 1);
343 dateStr
.append(my_i_to_a(buf
, sizeof(buf
)-1, aData
.Day
));
346 ((sql::PreparedStatement
*)cppStatement
)->setDateTime(parameter
, dateStr
);
347 } catch (const sql::MethodNotImplementedException
&) {
348 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setDate", *this);
349 } catch (const sql::SQLException
&e
) {
350 mysqlc_sdbc_driver::translateAndThrow(e
, *this, m_pConnection
->getConnectionEncoding());
356 /* {{{ OPreparedStatement::setTime() -I- */
357 void SAL_CALL
OPreparedStatement::setTime(sal_Int32 parameter
, const Time
& aVal
)
358 throw(SQLException
, RuntimeException
)
360 OSL_TRACE("OPreparedStatement::setTime");
361 MutexGuard
aGuard(m_aMutex
);
362 checkDisposed(OPreparedStatement::rBHelper
.bDisposed
);
363 checkParameterIndex(parameter
);
367 timeStr
.append(my_i_to_a(buf
, sizeof(buf
)-1, aVal
.Hours
));
368 timeStr
.append(":", 1);
369 timeStr
.append(my_i_to_a(buf
, sizeof(buf
)-1, aVal
.Minutes
));
370 timeStr
.append(":", 1);
371 timeStr
.append(my_i_to_a(buf
, sizeof(buf
)-1, aVal
.Seconds
));
374 ((sql::PreparedStatement
*)cppStatement
)->setDateTime(parameter
, timeStr
);
375 } catch (const sql::MethodNotImplementedException
&) {
376 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setTime", *this);
377 } catch (const sql::SQLException
&e
) {
378 mysqlc_sdbc_driver::translateAndThrow(e
, *this, m_pConnection
->getConnectionEncoding());
384 /* {{{ OPreparedStatement::setTimestamp() -I- */
385 void SAL_CALL
OPreparedStatement::setTimestamp(sal_Int32 parameter
, const DateTime
& aVal
)
386 throw(SQLException
, RuntimeException
)
388 OSL_TRACE("OPreparedStatement::setTimestamp");
389 MutexGuard
aGuard(m_aMutex
);
390 checkDisposed(OPreparedStatement::rBHelper
.bDisposed
);
391 checkParameterIndex(parameter
);
395 timeStr
.append(my_i_to_a(buf
, sizeof(buf
)-1, aVal
.Year
));
396 timeStr
.append("-", 1);
397 timeStr
.append(my_i_to_a(buf
, sizeof(buf
)-1, aVal
.Month
));
398 timeStr
.append("-", 1);
399 timeStr
.append(my_i_to_a(buf
, sizeof(buf
)-1, aVal
.Day
));
401 timeStr
.append(" ", 1);
403 timeStr
.append(my_i_to_a(buf
, sizeof(buf
)-1, aVal
.Hours
));
404 timeStr
.append(":", 1);
405 timeStr
.append(my_i_to_a(buf
, sizeof(buf
)-1, aVal
.Minutes
));
406 timeStr
.append(":", 1);
407 timeStr
.append(my_i_to_a(buf
, sizeof(buf
)-1, aVal
.Seconds
));
410 ((sql::PreparedStatement
*)cppStatement
)->setDateTime(parameter
, timeStr
);
411 } catch (const sql::MethodNotImplementedException
&) {
412 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setTimestamp", *this);
413 } catch (const sql::SQLException
&e
) {
414 mysqlc_sdbc_driver::translateAndThrow(e
, *this, m_pConnection
->getConnectionEncoding());
420 /* {{{ OPreparedStatement::setDouble() -I- */
421 void SAL_CALL
OPreparedStatement::setDouble(sal_Int32 parameter
, double x
)
422 throw(SQLException
, RuntimeException
)
424 OSL_TRACE("OPreparedStatement::setDouble");
425 MutexGuard
aGuard(m_aMutex
);
426 checkDisposed(OPreparedStatement::rBHelper
.bDisposed
);
427 checkParameterIndex(parameter
);
430 ((sql::PreparedStatement
*)cppStatement
)->setDouble(parameter
, x
);
431 } catch (const sql::MethodNotImplementedException
&) {
432 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setDouble", *this);
433 } catch (const sql::SQLException
&e
) {
434 mysqlc_sdbc_driver::translateAndThrow(e
, *this, m_pConnection
->getConnectionEncoding());
440 /* {{{ OPreparedStatement::setFloat() -I- */
441 void SAL_CALL
OPreparedStatement::setFloat(sal_Int32 parameter
, float x
)
442 throw(SQLException
, RuntimeException
)
444 OSL_TRACE("OPreparedStatement::setFloat");
445 MutexGuard
aGuard(m_aMutex
);
446 checkDisposed(OPreparedStatement::rBHelper
.bDisposed
);
447 checkParameterIndex(parameter
);
450 ((sql::PreparedStatement
*)cppStatement
)->setDouble(parameter
, x
);
451 } catch (const sql::MethodNotImplementedException
&) {
452 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setFloat", *this);
453 } catch (const sql::SQLException
&e
) {
454 mysqlc_sdbc_driver::translateAndThrow(e
, *this, m_pConnection
->getConnectionEncoding());
460 /* {{{ OPreparedStatement::setInt() -I- */
461 void SAL_CALL
OPreparedStatement::setInt(sal_Int32 parameter
, sal_Int32 x
)
462 throw(SQLException
, RuntimeException
)
464 OSL_TRACE("OPreparedStatement::setInt");
465 MutexGuard
aGuard(m_aMutex
);
466 checkDisposed(OPreparedStatement::rBHelper
.bDisposed
);
467 checkParameterIndex(parameter
);
470 ((sql::PreparedStatement
*)cppStatement
)->setInt(parameter
, x
);
471 } catch (const sql::MethodNotImplementedException
&) {
472 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setInt", *this);
473 } catch (const sql::SQLException
&e
) {
474 mysqlc_sdbc_driver::translateAndThrow(e
, *this, m_pConnection
->getConnectionEncoding());
480 /* {{{ OPreparedStatement::setLong() -I- */
481 void SAL_CALL
OPreparedStatement::setLong(sal_Int32 parameter
, sal_Int64 aVal
)
482 throw(SQLException
, RuntimeException
)
484 OSL_TRACE("OPreparedStatement::setLong");
485 MutexGuard
aGuard(m_aMutex
);
486 checkDisposed(OPreparedStatement::rBHelper
.bDisposed
);
487 checkParameterIndex(parameter
);
490 ((sql::PreparedStatement
*)cppStatement
)->setInt64(parameter
, aVal
);
491 } catch (const sql::MethodNotImplementedException
&) {
492 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setLong", *this);
493 } catch (const sql::SQLException
&e
) {
494 mysqlc_sdbc_driver::translateAndThrow(e
, *this, m_pConnection
->getConnectionEncoding());
500 /* {{{ OPreparedStatement::setNull() -I- */
501 void SAL_CALL
OPreparedStatement::setNull(sal_Int32 parameter
, sal_Int32 sqlType
)
502 throw(SQLException
, RuntimeException
)
504 OSL_TRACE("OPreparedStatement::setNull");
505 MutexGuard
aGuard(m_aMutex
);
506 checkDisposed(OPreparedStatement::rBHelper
.bDisposed
);
507 checkParameterIndex(parameter
);
510 ((sql::PreparedStatement
*)cppStatement
)->setNull(parameter
, sqlType
);
511 } catch (const sql::MethodNotImplementedException
&) {
512 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setNull", *this);
513 } catch (const sql::SQLException
&e
) {
514 mysqlc_sdbc_driver::translateAndThrow(e
, *this, m_pConnection
->getConnectionEncoding());
520 /* {{{ OPreparedStatement::setClob() -U- */
521 void SAL_CALL
OPreparedStatement::setClob(sal_Int32 parameter
, const Reference
< XClob
>& /* x */)
522 throw(SQLException
, RuntimeException
)
524 OSL_TRACE("OPreparedStatement::setClob");
525 MutexGuard
aGuard(m_aMutex
);
526 checkDisposed(OPreparedStatement::rBHelper
.bDisposed
);
527 checkParameterIndex(parameter
);
529 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setClob", *this);
534 /* {{{ OPreparedStatement::setBlob() -U- */
535 void SAL_CALL
OPreparedStatement::setBlob(sal_Int32 parameter
, const Reference
< XBlob
>& /* x */)
536 throw(SQLException
, RuntimeException
)
538 OSL_TRACE("OPreparedStatement::setBlob");
539 MutexGuard
aGuard(m_aMutex
);
540 checkDisposed(OPreparedStatement::rBHelper
.bDisposed
);
541 checkParameterIndex(parameter
);
543 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setBlob", *this);
548 /* {{{ OPreparedStatement::setArray() -U- */
549 void SAL_CALL
OPreparedStatement::setArray(sal_Int32 parameter
, const Reference
< XArray
>& /* x */)
550 throw(SQLException
, RuntimeException
)
552 OSL_TRACE("OPreparedStatement::setArray");
553 MutexGuard
aGuard(m_aMutex
);
554 checkDisposed(OPreparedStatement::rBHelper
.bDisposed
);
555 checkParameterIndex(parameter
);
557 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setArray", *this);
562 /* {{{ OPreparedStatement::setRef() -U- */
563 void SAL_CALL
OPreparedStatement::setRef(sal_Int32 parameter
, const Reference
< XRef
>& /* x */)
564 throw(SQLException
, RuntimeException
)
566 OSL_TRACE("OPreparedStatement::setRef");
567 MutexGuard
aGuard(m_aMutex
);
568 checkDisposed(OPreparedStatement::rBHelper
.bDisposed
);
569 checkParameterIndex(parameter
);
571 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setRef", *this);
577 template < class COMPLEXTYPE
>
578 bool impl_setObject( const Reference
< XParameters
>& _rxParam
, sal_Int32 _parameterIndex
, const Any
& _value
,
579 void ( SAL_CALL
XParameters::*_Setter
)( sal_Int32
, const COMPLEXTYPE
& ), bool _throwIfNotExtractable
)
582 if ( _value
>>= aValue
)
584 (_rxParam
.get()->*_Setter
)( _parameterIndex
, aValue
);
588 if ( _throwIfNotExtractable
)
589 mysqlc_sdbc_driver::throwInvalidArgumentException( "OPreparedStatement::setObjectWithInfo", _rxParam
);
593 template < class INTTYPE
>
594 void impl_setObject( const Reference
< XParameters
>& _rxParam
, sal_Int32 _parameterIndex
, const Any
& _value
,
595 void ( SAL_CALL
XParameters::*_Setter
)( sal_Int32
, INTTYPE
) )
598 if ( !( _value
>>= nValue
) )
599 mysqlc_sdbc_driver::throwInvalidArgumentException( "OPreparedStatement::setObjectWithInfo", _rxParam
);
600 (_rxParam
.get()->*_Setter
)( _parameterIndex
, (INTTYPE
)nValue
);
604 /* {{{ OPreparedStatement::setObjectWithInfo() -U- */
605 void SAL_CALL
OPreparedStatement::setObjectWithInfo(sal_Int32 _parameterIndex
, const Any
& _value
, sal_Int32 _targetSqlType
, sal_Int32
/* scale */)
606 throw(SQLException
, RuntimeException
)
608 OSL_TRACE("OPreparedStatement::setObjectWithInfo");
609 checkDisposed(OPreparedStatement::rBHelper
.bDisposed
);
610 MutexGuard
aGuard(m_aMutex
);
611 checkParameterIndex( _parameterIndex
);
613 if ( !_value
.hasValue() )
615 setNull( _parameterIndex
, _targetSqlType
);
619 switch ( _targetSqlType
)
621 case DataType::DECIMAL
:
622 case DataType::NUMERIC
:
625 if ( _value
>>= nValue
)
627 setDouble( _parameterIndex
, nValue
);
634 case DataType::VARCHAR
:
635 case DataType::LONGVARCHAR
:
636 impl_setObject( this, _parameterIndex
, _value
, &XParameters::setString
, true );
639 case DataType::BIGINT
:
641 sal_Int64 nValue
= 0;
642 if ( !( _value
>>= nValue
) )
643 mysqlc_sdbc_driver::throwInvalidArgumentException( "OPreparedStatement::setObjectWithInfo", *this );
644 setLong( _parameterIndex
, nValue
);
648 case DataType::FLOAT
:
652 if ( _value
>>= nValue
)
654 setFloat(_parameterIndex
,nValue
);
658 // run through if we couldn't set a float value
660 case DataType::DOUBLE
:
663 if ( !( _value
>>= nValue
) )
664 mysqlc_sdbc_driver::throwInvalidArgumentException( "OPreparedStatement::setObjectWithInfo", *this );
665 setDouble( _parameterIndex
, nValue
);
670 impl_setObject( this, _parameterIndex
, _value
, &XParameters::setDate
, true );
674 impl_setObject( this, _parameterIndex
, _value
, &XParameters::setTime
, true );
677 case DataType::TIMESTAMP
:
678 impl_setObject( this, _parameterIndex
, _value
, &XParameters::setTimestamp
, true );
681 case DataType::BINARY
:
682 case DataType::VARBINARY
:
683 case DataType::LONGVARBINARY
:
685 if ( impl_setObject( this, _parameterIndex
, _value
, &XParameters::setBytes
, false )
686 || impl_setObject( this, _parameterIndex
, _value
, &XParameters::setBlob
, false )
687 || impl_setObject( this, _parameterIndex
, _value
, &XParameters::setClob
, false )
691 Reference
< ::com::sun::star::io::XInputStream
> xBinStream
;
692 if ( _value
>>= xBinStream
)
694 setBinaryStream( _parameterIndex
, xBinStream
, xBinStream
->available() );
698 mysqlc_sdbc_driver::throwInvalidArgumentException( "OPreparedStatement::setObjectWithInfo", *this );
703 case DataType::BOOLEAN
:
705 bool bValue( false );
706 if ( _value
>>= bValue
)
708 setBoolean( _parameterIndex
, bValue
);
711 sal_Int32
nValue( 0 );
712 if ( _value
>>= nValue
)
714 setBoolean( _parameterIndex
, ( nValue
!= 0 ) );
717 mysqlc_sdbc_driver::throwInvalidArgumentException( "OPreparedStatement::setObjectWithInfo", *this );
721 case DataType::TINYINT
:
722 impl_setObject( this, _parameterIndex
, _value
, &XParameters::setByte
);
725 case DataType::SMALLINT
:
726 impl_setObject( this, _parameterIndex
, _value
, &XParameters::setShort
);
729 case DataType::INTEGER
:
730 impl_setObject( this, _parameterIndex
, _value
, &XParameters::setInt
);
734 mysqlc_sdbc_driver::throwInvalidArgumentException( "OPreparedStatement::setObjectWithInfo", *this );
741 /* {{{ OPreparedStatement::setObjectNull() -U- */
742 void SAL_CALL
OPreparedStatement::setObjectNull(sal_Int32 parameter
, sal_Int32
/* sqlType */, const OUString
& /* typeName */)
743 throw(SQLException
, RuntimeException
)
745 OSL_TRACE("OPreparedStatement::setObjectNull");
746 MutexGuard
aGuard(m_aMutex
);
747 checkDisposed(OPreparedStatement::rBHelper
.bDisposed
);
748 checkParameterIndex(parameter
);
750 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setObjectNull", *this);
755 /* {{{ OPreparedStatement::setObject() -U- */
756 void SAL_CALL
OPreparedStatement::setObject(sal_Int32 parameter
, const Any
& /* x */)
757 throw(SQLException
, RuntimeException
)
759 OSL_TRACE("OPreparedStatement::setObject");
760 MutexGuard
aGuard(m_aMutex
);
761 checkDisposed(OPreparedStatement::rBHelper
.bDisposed
);
762 checkParameterIndex(parameter
);
764 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setObject", *this);
769 /* {{{ OPreparedStatement::setShort() -I- */
770 void SAL_CALL
OPreparedStatement::setShort(sal_Int32 parameter
, sal_Int16 x
)
771 throw(SQLException
, RuntimeException
)
773 OSL_TRACE("OPreparedStatement::setShort");
774 MutexGuard
aGuard(m_aMutex
);
775 checkDisposed(OPreparedStatement::rBHelper
.bDisposed
);
776 checkParameterIndex(parameter
);
779 ((sql::PreparedStatement
*)cppStatement
)->setInt(parameter
, x
);
780 } catch (const sql::MethodNotImplementedException
&) {
781 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setShort", *this);
782 } catch (const sql::SQLException
&e
) {
783 mysqlc_sdbc_driver::translateAndThrow(e
, *this, m_pConnection
->getConnectionEncoding());
789 /* {{{ OPreparedStatement::setBytes() -I- */
790 void SAL_CALL
OPreparedStatement::setBytes(sal_Int32 parameter
, const Sequence
< sal_Int8
>& x
)
791 throw(SQLException
, RuntimeException
)
793 OSL_TRACE("OPreparedStatement::setBytes");
794 MutexGuard
aGuard(m_aMutex
);
795 checkDisposed(OPreparedStatement::rBHelper
.bDisposed
);
796 checkParameterIndex(parameter
);
798 std::string
blobby((char *)x
.getConstArray(), x
.getLength());
800 ((sql::PreparedStatement
*)cppStatement
)->setString(parameter
, blobby
);
801 } catch (const sql::MethodNotImplementedException
&) {
802 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setBytes", *this);
803 } catch (const sql::SQLException
&e
) {
804 mysqlc_sdbc_driver::translateAndThrow(e
, *this, m_pConnection
->getConnectionEncoding());
810 /* {{{ OPreparedStatement::setCharacterStream() -U- */
811 void SAL_CALL
OPreparedStatement::setCharacterStream(sal_Int32 parameter
,
812 const Reference
< XInputStream
>& /* x */,
813 sal_Int32
/* length */)
814 throw(SQLException
, RuntimeException
)
816 OSL_TRACE("OPreparedStatement::setCharacterStream");
817 MutexGuard
aGuard(m_aMutex
);
818 checkDisposed(OPreparedStatement::rBHelper
.bDisposed
);
819 checkParameterIndex(parameter
);
821 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setCharacterStream", *this);
826 /* {{{ OPreparedStatement::setBinaryStream() -U- */
827 void SAL_CALL
OPreparedStatement::setBinaryStream(sal_Int32 parameter
,
828 const Reference
< XInputStream
>& /* x */,
829 sal_Int32
/* length */)
830 throw(SQLException
, RuntimeException
)
832 OSL_TRACE("OPreparedStatement::setBinaryStream");
833 MutexGuard
aGuard(m_aMutex
);
834 checkDisposed(OPreparedStatement::rBHelper
.bDisposed
);
835 checkParameterIndex(parameter
);
837 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setBinaryStream", *this);
842 /* {{{ OPreparedStatement::clearParameters() -I- */
843 void SAL_CALL
OPreparedStatement::clearParameters()
844 throw(SQLException
, RuntimeException
)
846 OSL_TRACE("OPreparedStatement::clearParameters");
847 MutexGuard
aGuard(m_aMutex
);
848 checkDisposed(OPreparedStatement::rBHelper
.bDisposed
);
851 ((sql::PreparedStatement
*)cppStatement
)->clearParameters();
852 } catch (const sql::MethodNotImplementedException
&) {
853 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::clearParameters", *this);
854 } catch (const sql::SQLException
&e
) {
855 mysqlc_sdbc_driver::translateAndThrow(e
, *this, m_pConnection
->getConnectionEncoding());
861 /* {{{ OPreparedStatement::clearBatch() -U- */
862 void SAL_CALL
OPreparedStatement::clearBatch()
863 throw(SQLException
, RuntimeException
)
865 OSL_TRACE("OPreparedStatement::clearBatch");
866 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::clearBatch", *this);
871 /* {{{ OPreparedStatement::addBatch() -U- */
872 void SAL_CALL
OPreparedStatement::addBatch()
873 throw(SQLException
, RuntimeException
)
875 OSL_TRACE("OPreparedStatement::addBatch");
876 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::addBatch", *this);
881 /* {{{ OPreparedStatement::executeBatch() -I- */
882 Sequence
< sal_Int32
> SAL_CALL
OPreparedStatement::executeBatch()
883 throw(SQLException
, RuntimeException
)
885 OSL_TRACE("OPreparedStatement::executeBatch");
886 Sequence
< sal_Int32
> aRet
= Sequence
< sal_Int32
> ();
892 /* {{{ OPreparedStatement::setFastPropertyValue_NoBroadcast() -I- */
893 void OPreparedStatement::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle
,const Any
& rValue
)
896 OSL_TRACE("OPreparedStatement::setFastPropertyValue_NoBroadcast");
899 case PROPERTY_ID_RESULTSETCONCURRENCY
:
901 case PROPERTY_ID_RESULTSETTYPE
:
903 case PROPERTY_ID_FETCHDIRECTION
:
905 case PROPERTY_ID_USEBOOKMARKS
:
908 /* XXX: Recursion ?? */
909 OPreparedStatement::setFastPropertyValue_NoBroadcast(nHandle
,rValue
);
915 /* {{{ OPreparedStatement::checkParameterIndex() -I- */
916 void OPreparedStatement::checkParameterIndex(sal_Int32 column
)
918 OSL_TRACE("OPreparedStatement::checkColumnIndex");
919 if (column
< 1 || column
> (sal_Int32
) m_paramCount
) {
920 OUString
buf( RTL_CONSTASCII_USTRINGPARAM( "Parameter index out of range" ) );
921 throw SQLException(buf
, *this, OUString(), 1, Any ());
932 * vim600: noet sw=4 ts=4 fdm=marker
933 * vim<600: noet sw=4 ts=4
936 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */