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