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