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>
39 #define snprintf _snprintf
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
);
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();
75 m_paramCount
= ((sql::PreparedStatement
*)cppStatement
)->getParameterMetaData()->getParameterCount();
76 } catch (const sql::SQLException
&e
) {
77 mysqlc_sdbc_driver::translateAndThrow(e
, *this, m_pConnection
->getConnectionEncoding());
83 /* {{{ OPreparedStatement::~OPreparedStatement() -I- */
84 OPreparedStatement::~OPreparedStatement()
86 OSL_TRACE("OPreparedStatement::~OPreparedStatement");
91 /* {{{ OPreparedStatement::acquire() -I- */
92 void SAL_CALL
OPreparedStatement::acquire()
95 OSL_TRACE("OPreparedStatement::acquire");
96 OCommonStatement::acquire();
101 /* {{{ OPreparedStatement::release() -I- */
102 void SAL_CALL
OPreparedStatement::release()
105 OSL_TRACE("OPreparedStatement::release");
106 OCommonStatement::release();
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
);
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());
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
);
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());
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
);
172 OCommonStatement::close();
173 } catch (const SQLException
&) {
174 // If we get an error, ignore
177 // Remove this Statement object from the Connection object's
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
;
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());
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;
212 affectedRows
= ((sql::PreparedStatement
*)cppStatement
)->executeUpdate();
213 } catch (const sql::SQLException
&e
) {
214 mysqlc_sdbc_driver::translateAndThrow(e
, *this, m_pConnection
->getConnectionEncoding());
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
);
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());
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
;
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
;
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());
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
);
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());
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
);
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());
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
);
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
));
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());
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
);
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
));
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());
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
);
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
));
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());
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
);
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());
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
);
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());
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
);
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());
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
);
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());
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
);
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());
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);
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);
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);
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);
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
)
586 if ( _value
>>= aValue
)
588 (_rxParam
.get()->*_Setter
)( _parameterIndex
, aValue
);
592 if ( _throwIfNotExtractable
)
593 mysqlc_sdbc_driver::throwInvalidArgumentException( "OPreparedStatement::setObjectWithInfo", _rxParam
);
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
) )
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
);
623 switch ( _targetSqlType
)
625 case DataType::DECIMAL
:
626 case DataType::NUMERIC
:
629 if ( _value
>>= nValue
)
631 setDouble( _parameterIndex
, nValue
);
638 case DataType::VARCHAR
:
639 case DataType::LONGVARCHAR
:
640 impl_setObject( this, _parameterIndex
, _value
, &XParameters::setString
, true );
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
);
652 case DataType::FLOAT
:
656 if ( _value
>>= nValue
)
658 setFloat(_parameterIndex
,nValue
);
662 // run through if we couldn't set a float value
664 case DataType::DOUBLE
:
667 if ( !( _value
>>= nValue
) )
668 mysqlc_sdbc_driver::throwInvalidArgumentException( "OPreparedStatement::setObjectWithInfo", *this );
669 setDouble( _parameterIndex
, nValue
);
674 impl_setObject( this, _parameterIndex
, _value
, &XParameters::setDate
, true );
678 impl_setObject( this, _parameterIndex
, _value
, &XParameters::setTime
, true );
681 case DataType::TIMESTAMP
:
682 impl_setObject( this, _parameterIndex
, _value
, &XParameters::setTimestamp
, true );
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 )
695 Reference
< ::com::sun::star::io::XInputStream
> xBinStream
;
696 if ( _value
>>= xBinStream
)
698 setBinaryStream( _parameterIndex
, xBinStream
, xBinStream
->available() );
702 mysqlc_sdbc_driver::throwInvalidArgumentException( "OPreparedStatement::setObjectWithInfo", *this );
707 case DataType::BOOLEAN
:
709 bool bValue( false );
710 if ( _value
>>= bValue
)
712 setBoolean( _parameterIndex
, bValue
);
715 sal_Int32
nValue( 0 );
716 if ( _value
>>= nValue
)
718 setBoolean( _parameterIndex
, ( nValue
!= 0 ) );
721 mysqlc_sdbc_driver::throwInvalidArgumentException( "OPreparedStatement::setObjectWithInfo", *this );
725 case DataType::TINYINT
:
726 impl_setObject( this, _parameterIndex
, _value
, &XParameters::setByte
);
729 case DataType::SMALLINT
:
730 impl_setObject( this, _parameterIndex
, _value
, &XParameters::setShort
);
733 case DataType::INTEGER
:
734 impl_setObject( this, _parameterIndex
, _value
, &XParameters::setInt
);
738 mysqlc_sdbc_driver::throwInvalidArgumentException( "OPreparedStatement::setObjectWithInfo", *this );
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);
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);
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
);
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());
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());
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());
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);
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);
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
);
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());
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);
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);
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
> ();
896 /* {{{ OPreparedStatement::setFastPropertyValue_NoBroadcast() -I- */
897 void OPreparedStatement::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle
,const Any
& rValue
)
900 OSL_TRACE("OPreparedStatement::setFastPropertyValue_NoBroadcast");
903 case PROPERTY_ID_RESULTSETCONCURRENCY
:
905 case PROPERTY_ID_RESULTSETTYPE
:
907 case PROPERTY_ID_FETCHDIRECTION
:
909 case PROPERTY_ID_USEBOOKMARKS
:
912 /* XXX: Recursion ?? */
913 OPreparedStatement::setFastPropertyValue_NoBroadcast(nHandle
,rValue
);
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 ());
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: */