Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include "Connection.hxx"
21 : #include "PreparedStatement.hxx"
22 : #include "ResultSet.hxx"
23 : #include "ResultSetMetaData.hxx"
24 : #include "Util.hxx"
25 :
26 : #include <comphelper/sequence.hxx>
27 : #include <connectivity/dbexception.hxx>
28 : #include <cppuhelper/typeprovider.hxx>
29 : #include <osl/diagnose.h>
30 : #include <propertyids.hxx>
31 : #include <time.h>
32 :
33 : #include <com/sun/star/sdbc/DataType.hpp>
34 : #include <com/sun/star/lang/DisposedException.hpp>
35 :
36 : using namespace connectivity::firebird;
37 :
38 : using namespace ::comphelper;
39 : using namespace ::osl;
40 :
41 : using namespace com::sun::star;
42 : using namespace com::sun::star::uno;
43 : using namespace com::sun::star::lang;
44 : using namespace com::sun::star::beans;
45 : using namespace com::sun::star::sdbc;
46 : using namespace com::sun::star::container;
47 : using namespace com::sun::star::io;
48 : using namespace com::sun::star::util;
49 :
50 0 : IMPLEMENT_SERVICE_INFO(OPreparedStatement,"com.sun.star.sdbcx.firebird.PreparedStatement","com.sun.star.sdbc.PreparedStatement");
51 :
52 :
53 0 : OPreparedStatement::OPreparedStatement( Connection* _pConnection,
54 : const TTypeInfoVector& _TypeInfo,
55 : const OUString& sql)
56 : :OStatementCommonBase(_pConnection)
57 : ,m_aTypeInfo(_TypeInfo)
58 : ,m_sSqlStatement(sql)
59 : ,m_pOutSqlda(0)
60 0 : ,m_pInSqlda(0)
61 : {
62 : SAL_INFO("connectivity.firebird", "OPreparedStatement(). "
63 : "sql: " << sql);
64 0 : }
65 :
66 0 : void OPreparedStatement::ensurePrepared()
67 : throw (SQLException, RuntimeException)
68 : {
69 0 : MutexGuard aGuard(m_aMutex);
70 0 : checkDisposed(OStatementCommonBase_Base::rBHelper.bDisposed);
71 :
72 0 : if (m_aStatementHandle)
73 0 : return;
74 :
75 0 : ISC_STATUS aErr = 0;
76 :
77 0 : if (!m_pInSqlda)
78 : {
79 0 : m_pInSqlda = (XSQLDA*) calloc(1, XSQLDA_LENGTH(10));
80 0 : m_pInSqlda->version = SQLDA_VERSION1;
81 0 : m_pInSqlda->sqln = 10;
82 : }
83 :
84 : prepareAndDescribeStatement(m_sSqlStatement,
85 : m_pOutSqlda,
86 0 : m_pInSqlda);
87 :
88 :
89 : aErr = isc_dsql_describe_bind(m_statusVector,
90 : &m_aStatementHandle,
91 : 1,
92 0 : m_pInSqlda);
93 :
94 0 : if (aErr)
95 : {
96 : SAL_WARN("connectivity.firebird", "isc_dsql_describe_bind failed");
97 : }
98 0 : else if (m_pInSqlda->sqld > m_pInSqlda->sqln) // Not large enough
99 : {
100 0 : short nItems = m_pInSqlda->sqld;
101 0 : free(m_pInSqlda);
102 0 : m_pInSqlda = (XSQLDA*) calloc(1, XSQLDA_LENGTH(nItems));
103 0 : m_pInSqlda->version = SQLDA_VERSION1;
104 0 : m_pInSqlda->sqln = nItems;
105 : isc_dsql_describe_bind(m_statusVector,
106 : &m_aStatementHandle,
107 : 1,
108 0 : m_pInSqlda);
109 : }
110 :
111 0 : if (!aErr)
112 0 : mallocSQLVAR(m_pInSqlda);
113 : else
114 0 : evaluateStatusVector(m_statusVector, m_sSqlStatement, *this);
115 : }
116 :
117 0 : OPreparedStatement::~OPreparedStatement()
118 : {
119 0 : }
120 :
121 0 : void SAL_CALL OPreparedStatement::acquire() throw()
122 : {
123 0 : OStatementCommonBase::acquire();
124 0 : }
125 :
126 0 : void SAL_CALL OPreparedStatement::release() throw()
127 : {
128 0 : OStatementCommonBase::release();
129 0 : }
130 :
131 0 : Any SAL_CALL OPreparedStatement::queryInterface(const Type& rType)
132 : throw(RuntimeException, std::exception)
133 : {
134 0 : Any aRet = OStatementCommonBase::queryInterface(rType);
135 0 : if(!aRet.hasValue())
136 0 : aRet = OPreparedStatement_Base::queryInterface(rType);
137 0 : return aRet;
138 : }
139 :
140 0 : uno::Sequence< Type > SAL_CALL OPreparedStatement::getTypes()
141 : throw(RuntimeException, std::exception)
142 : {
143 : return concatSequences(OPreparedStatement_Base::getTypes(),
144 0 : OStatementCommonBase::getTypes());
145 : }
146 :
147 0 : Reference< XResultSetMetaData > SAL_CALL OPreparedStatement::getMetaData()
148 : throw(SQLException, RuntimeException, std::exception)
149 : {
150 0 : ::osl::MutexGuard aGuard( m_aMutex );
151 0 : checkDisposed(OStatementCommonBase_Base::rBHelper.bDisposed);
152 0 : ensurePrepared();
153 :
154 0 : if(!m_xMetaData.is())
155 0 : m_xMetaData = new OResultSetMetaData(m_pConnection.get(), m_pOutSqlda);
156 :
157 0 : return m_xMetaData;
158 : }
159 :
160 0 : void SAL_CALL OPreparedStatement::close() throw(SQLException, RuntimeException, std::exception)
161 : {
162 0 : MutexGuard aGuard( m_aMutex );
163 0 : checkDisposed(OStatementCommonBase_Base::rBHelper.bDisposed);
164 :
165 0 : OStatementCommonBase::close();
166 0 : if (m_pInSqlda)
167 : {
168 0 : freeSQLVAR(m_pInSqlda);
169 0 : free(m_pInSqlda);
170 0 : m_pInSqlda = 0;
171 : }
172 0 : if (m_pOutSqlda)
173 : {
174 0 : freeSQLVAR(m_pOutSqlda);
175 0 : free(m_pOutSqlda);
176 0 : m_pOutSqlda = 0;
177 0 : }
178 0 : }
179 :
180 0 : void SAL_CALL OPreparedStatement::disposing()
181 : {
182 0 : close();
183 0 : }
184 :
185 0 : void SAL_CALL OPreparedStatement::setString(sal_Int32 nParameterIndex,
186 : const OUString& x)
187 : throw(SQLException, RuntimeException, std::exception)
188 : {
189 : SAL_INFO("connectivity.firebird",
190 : "setString(" << nParameterIndex << " , " << x << ")");
191 :
192 0 : MutexGuard aGuard( m_aMutex );
193 0 : checkDisposed(OStatementCommonBase_Base::rBHelper.bDisposed);
194 0 : ensurePrepared();
195 :
196 0 : checkParameterIndex(nParameterIndex);
197 0 : setParameterNull(nParameterIndex, false);
198 :
199 0 : OString str = OUStringToOString(x , RTL_TEXTENCODING_UTF8 );
200 :
201 0 : XSQLVAR* pVar = m_pInSqlda->sqlvar + (nParameterIndex - 1);
202 :
203 0 : int dtype = (pVar->sqltype & ~1); // drop flag bit for now
204 :
205 0 : if (str.getLength() > pVar->sqllen)
206 0 : str = str.copy(0, pVar->sqllen);
207 :
208 0 : switch (dtype) {
209 : case SQL_VARYING:
210 : {
211 0 : const sal_Int32 max_varchar_len = 0xFFFF;
212 : // First 2 bytes indicate string size
213 0 : if (str.getLength() > max_varchar_len)
214 : {
215 0 : str = str.copy(0, max_varchar_len);
216 : }
217 0 : const short nLength = str.getLength();
218 0 : memcpy(pVar->sqldata, &nLength, 2);
219 : // Actual data
220 0 : memcpy(pVar->sqldata + 2, str.getStr(), str.getLength());
221 0 : break;
222 : }
223 : case SQL_TEXT:
224 0 : memcpy(pVar->sqldata, str.getStr(), str.getLength());
225 : // Fill remainder with spaces
226 0 : memset(pVar->sqldata + str.getLength(), ' ', pVar->sqllen - str.getLength());
227 0 : break;
228 : default:
229 : ::dbtools::throwSQLException(
230 : "Incorrect type for setString",
231 : ::dbtools::SQL_INVALID_SQL_DATA_TYPE,
232 0 : *this);
233 0 : }
234 0 : }
235 :
236 0 : Reference< XConnection > SAL_CALL OPreparedStatement::getConnection()
237 : throw(SQLException, RuntimeException, std::exception)
238 : {
239 0 : MutexGuard aGuard( m_aMutex );
240 0 : checkDisposed(OStatementCommonBase_Base::rBHelper.bDisposed);
241 :
242 0 : return Reference<XConnection>(m_pConnection.get());
243 : }
244 :
245 0 : sal_Bool SAL_CALL OPreparedStatement::execute()
246 : throw(SQLException, RuntimeException, std::exception)
247 : {
248 : SAL_INFO("connectivity.firebird", "executeQuery(). "
249 : "Got called with sql: " << m_sSqlStatement);
250 :
251 0 : MutexGuard aGuard( m_aMutex );
252 0 : checkDisposed(OStatementCommonBase_Base::rBHelper.bDisposed);
253 :
254 0 : ensurePrepared();
255 :
256 : ISC_STATUS aErr;
257 :
258 0 : if (m_xResultSet.is()) // Checks whether we have already run the statement.
259 : {
260 0 : disposeResultSet();
261 : // Closes the cursor from the last run.
262 : // This doesn't actually free the statement -- using DSQL_close closes
263 : // the cursor and keeps the statement, using DSQL_drop frees the statement
264 : // (and associated cursors).
265 : aErr = isc_dsql_free_statement(m_statusVector,
266 : &m_aStatementHandle,
267 0 : DSQL_close);
268 0 : if (aErr)
269 : evaluateStatusVector(m_statusVector,
270 : "isc_dsql_free_statement: close cursor",
271 0 : *this);
272 : }
273 :
274 : aErr = isc_dsql_execute(m_statusVector,
275 0 : &m_pConnection->getTransaction(),
276 : &m_aStatementHandle,
277 : 1,
278 0 : m_pInSqlda);
279 0 : if (aErr)
280 : {
281 : SAL_WARN("connectivity.firebird", "isc_dsql_execute failed" );
282 0 : evaluateStatusVector(m_statusVector, "isc_dsql_execute", *this);
283 : }
284 :
285 0 : m_xResultSet = new OResultSet(m_pConnection.get(),
286 : m_aMutex,
287 : uno::Reference< XInterface >(*this),
288 : m_aStatementHandle,
289 0 : m_pOutSqlda);
290 :
291 0 : if (getStatementChangeCount() > 0)
292 0 : m_pConnection->notifyDatabaseModified();
293 :
294 0 : return m_xResultSet.is();
295 : // TODO: implement handling of multiple ResultSets.
296 : }
297 :
298 0 : sal_Int32 SAL_CALL OPreparedStatement::executeUpdate()
299 : throw(SQLException, RuntimeException, std::exception)
300 : {
301 0 : execute();
302 0 : return getStatementChangeCount();
303 : }
304 :
305 0 : Reference< XResultSet > SAL_CALL OPreparedStatement::executeQuery()
306 : throw(SQLException, RuntimeException, std::exception)
307 : {
308 0 : execute();
309 0 : return m_xResultSet;
310 : }
311 :
312 : //----- XParameters -----------------------------------------------------------
313 0 : void SAL_CALL OPreparedStatement::setNull(sal_Int32 nIndex, sal_Int32 /*nSqlType*/)
314 : throw(SQLException, RuntimeException, std::exception)
315 : {
316 0 : MutexGuard aGuard( m_aMutex );
317 0 : checkDisposed(OStatementCommonBase_Base::rBHelper.bDisposed);
318 0 : ensurePrepared();
319 :
320 0 : setParameterNull(nIndex, true);
321 0 : }
322 :
323 0 : void SAL_CALL OPreparedStatement::setBoolean(sal_Int32 /*nIndex*/, sal_Bool /*bValue*/)
324 : throw(SQLException, RuntimeException, std::exception)
325 : {
326 : // FIREBIRD3: will need to be implemented.
327 0 : ::dbtools::throwFunctionNotSupportedSQLException("XParameters::setBoolean", *this);
328 0 : }
329 :
330 : template <typename T>
331 0 : void OPreparedStatement::setValue(sal_Int32 nIndex, T& nValue, ISC_SHORT nType)
332 : throw(SQLException, RuntimeException)
333 : {
334 0 : MutexGuard aGuard( m_aMutex );
335 0 : checkDisposed(OStatementCommonBase_Base::rBHelper.bDisposed);
336 0 : ensurePrepared();
337 :
338 0 : checkParameterIndex(nIndex);
339 0 : setParameterNull(nIndex, false);
340 :
341 0 : XSQLVAR* pVar = m_pInSqlda->sqlvar + (nIndex - 1);
342 :
343 0 : if ((pVar->sqltype & ~1) != nType)
344 : {
345 0 : ::dbtools::throwSQLException(
346 : "Incorrect type for setString",
347 : ::dbtools::SQL_INVALID_SQL_DATA_TYPE,
348 0 : *this);
349 : }
350 :
351 0 : memcpy(pVar->sqldata, &nValue, sizeof(nValue));
352 0 : }
353 :
354 0 : void SAL_CALL OPreparedStatement::setByte(sal_Int32 /*nIndex*/, sal_Int8 /*nValue*/)
355 : throw(SQLException, RuntimeException, std::exception)
356 : {
357 0 : ::dbtools::throwFunctionNotSupportedSQLException("XParameters::setByte", *this);
358 0 : }
359 :
360 0 : void SAL_CALL OPreparedStatement::setShort(sal_Int32 nIndex, sal_Int16 nValue)
361 : throw(SQLException, RuntimeException, std::exception)
362 : {
363 0 : setValue< sal_Int16 >(nIndex, nValue, SQL_SHORT);
364 0 : }
365 :
366 0 : void SAL_CALL OPreparedStatement::setInt(sal_Int32 nIndex, sal_Int32 nValue)
367 : throw(SQLException, RuntimeException, std::exception)
368 : {
369 0 : setValue< sal_Int32 >(nIndex, nValue, SQL_LONG);
370 0 : }
371 :
372 0 : void SAL_CALL OPreparedStatement::setLong(sal_Int32 nIndex, sal_Int64 nValue)
373 : throw(SQLException, RuntimeException, std::exception)
374 : {
375 0 : setValue< sal_Int64 >(nIndex, nValue, SQL_INT64);
376 0 : }
377 :
378 0 : void SAL_CALL OPreparedStatement::setFloat(sal_Int32 nIndex, float nValue)
379 : throw(SQLException, RuntimeException, std::exception)
380 : {
381 0 : setValue< float >(nIndex, nValue, SQL_FLOAT);
382 0 : }
383 :
384 0 : void SAL_CALL OPreparedStatement::setDouble(sal_Int32 nIndex, double nValue)
385 : throw(SQLException, RuntimeException, std::exception)
386 : {
387 0 : setValue< double >(nIndex, nValue, SQL_DOUBLE); // TODO: SQL_D_FLOAT?
388 0 : }
389 :
390 0 : void SAL_CALL OPreparedStatement::setDate(sal_Int32 nIndex, const Date& rDate)
391 : throw(SQLException, RuntimeException, std::exception)
392 : {
393 : struct tm aCTime;
394 0 : aCTime.tm_mday = rDate.Day;
395 0 : aCTime.tm_mon = rDate.Month;
396 0 : aCTime.tm_year = rDate.Year;
397 :
398 : ISC_DATE aISCDate;
399 0 : isc_encode_sql_date(&aCTime, &aISCDate);
400 :
401 0 : setValue< ISC_DATE >(nIndex, aISCDate, SQL_TYPE_DATE);
402 0 : }
403 :
404 0 : void SAL_CALL OPreparedStatement::setTime( sal_Int32 nIndex, const css::util::Time& rTime)
405 : throw(SQLException, RuntimeException, std::exception)
406 : {
407 : struct tm aCTime;
408 0 : aCTime.tm_sec = rTime.Seconds;
409 0 : aCTime.tm_min = rTime.Minutes;
410 0 : aCTime.tm_hour = rTime.Hours;
411 :
412 : ISC_TIME aISCTime;
413 0 : isc_encode_sql_time(&aCTime, &aISCTime);
414 :
415 0 : setValue< ISC_TIME >(nIndex, aISCTime, SQL_TYPE_TIME);
416 0 : }
417 :
418 0 : void SAL_CALL OPreparedStatement::setTimestamp(sal_Int32 nIndex, const DateTime& rTimestamp)
419 : throw(SQLException, RuntimeException, std::exception)
420 : {
421 : struct tm aCTime;
422 0 : aCTime.tm_sec = rTimestamp.Seconds;
423 0 : aCTime.tm_min = rTimestamp.Minutes;
424 0 : aCTime.tm_hour = rTimestamp.Hours;
425 0 : aCTime.tm_mday = rTimestamp.Day;
426 0 : aCTime.tm_mon = rTimestamp.Month;
427 0 : aCTime.tm_year = rTimestamp.Year;
428 :
429 : ISC_TIMESTAMP aISCTimestamp;
430 0 : isc_encode_timestamp(&aCTime, &aISCTimestamp);
431 :
432 0 : setValue< ISC_TIMESTAMP >(nIndex, aISCTimestamp, SQL_TIMESTAMP);
433 0 : }
434 :
435 :
436 : // void OPreaparedStatement::set
437 0 : void OPreparedStatement::openBlobForWriting(isc_blob_handle& rBlobHandle, ISC_QUAD& rBlobId)
438 : {
439 : ISC_STATUS aErr;
440 :
441 : aErr = isc_create_blob2(m_statusVector,
442 0 : &m_pConnection->getDBHandle(),
443 0 : &m_pConnection->getTransaction(),
444 : &rBlobHandle,
445 : &rBlobId,
446 : 0, // Blob parameter buffer length
447 0 : 0); // Blob parameter buffer handle
448 :
449 0 : if (aErr)
450 : {
451 : evaluateStatusVector(m_statusVector,
452 0 : "setBlob failed on " + m_sSqlStatement,
453 0 : *this);
454 : assert(false);
455 : }
456 0 : }
457 :
458 0 : void OPreparedStatement::closeBlobAfterWriting(isc_blob_handle& rBlobHandle)
459 : {
460 : ISC_STATUS aErr;
461 :
462 : aErr = isc_close_blob(m_statusVector,
463 0 : &rBlobHandle);
464 0 : if (aErr)
465 : {
466 : evaluateStatusVector(m_statusVector,
467 : "isc_close_blob failed",
468 0 : *this);
469 : assert(false);
470 : }
471 0 : }
472 :
473 0 : void SAL_CALL OPreparedStatement::setClob( sal_Int32 parameterIndex, const Reference< XClob >& x ) throw(SQLException, RuntimeException, std::exception)
474 : {
475 : (void) parameterIndex;
476 : (void) x;
477 0 : ::osl::MutexGuard aGuard( m_aMutex );
478 0 : checkDisposed(OStatementCommonBase_Base::rBHelper.bDisposed);
479 :
480 0 : }
481 :
482 0 : void SAL_CALL OPreparedStatement::setBlob(sal_Int32 nParameterIndex,
483 : const Reference< XBlob >& xBlob)
484 : throw (SQLException, RuntimeException, std::exception)
485 : {
486 0 : ::osl::MutexGuard aGuard(m_aMutex);
487 0 : checkDisposed(OStatementCommonBase_Base::rBHelper.bDisposed);
488 :
489 0 : isc_blob_handle aBlobHandle = 0;
490 : ISC_QUAD aBlobId;
491 :
492 0 : openBlobForWriting(aBlobHandle, aBlobId);
493 :
494 : // Max segment size is 2^16 == SAL_MAX_UINT16
495 : // LEM TODO: SAL_MAX_UINT16 is 2^16-1; this mixup is probably innocuous; to be checked
496 0 : sal_uInt64 nDataWritten = 0;
497 0 : ISC_STATUS aErr = 0;
498 0 : while (xBlob->length() - nDataWritten > 0)
499 : {
500 0 : sal_uInt64 nDataRemaining = xBlob->length() - nDataWritten;
501 0 : sal_uInt16 nWriteSize = (nDataRemaining > SAL_MAX_UINT16) ? SAL_MAX_UINT16 : nDataRemaining;
502 : aErr = isc_put_segment(m_statusVector,
503 : &aBlobHandle,
504 : nWriteSize,
505 0 : (const char*) xBlob->getBytes(nDataWritten, nWriteSize).getConstArray());
506 0 : nDataWritten += nWriteSize;
507 :
508 :
509 0 : if (aErr)
510 0 : break;
511 :
512 : }
513 :
514 : // We need to make sure we close the Blob even if their are errors, hence evaluate
515 : // errors after closing.
516 0 : closeBlobAfterWriting(aBlobHandle);
517 :
518 0 : if (aErr)
519 : {
520 : evaluateStatusVector(m_statusVector,
521 : "isc_put_segment failed",
522 0 : *this);
523 : assert(false);
524 : }
525 :
526 0 : setValue< ISC_QUAD >(nParameterIndex, aBlobId, SQL_BLOB);
527 0 : }
528 :
529 :
530 :
531 0 : void SAL_CALL OPreparedStatement::setArray( sal_Int32 parameterIndex, const Reference< XArray >& x ) throw(SQLException, RuntimeException, std::exception)
532 : {
533 : (void) parameterIndex;
534 : (void) x;
535 0 : ::osl::MutexGuard aGuard( m_aMutex );
536 0 : checkDisposed(OStatementCommonBase_Base::rBHelper.bDisposed);
537 :
538 0 : }
539 :
540 :
541 0 : void SAL_CALL OPreparedStatement::setRef( sal_Int32 parameterIndex, const Reference< XRef >& x ) throw(SQLException, RuntimeException, std::exception)
542 : {
543 : (void) parameterIndex;
544 : (void) x;
545 0 : ::osl::MutexGuard aGuard( m_aMutex );
546 0 : checkDisposed(OStatementCommonBase_Base::rBHelper.bDisposed);
547 :
548 0 : }
549 :
550 :
551 0 : void SAL_CALL OPreparedStatement::setObjectWithInfo( sal_Int32 parameterIndex, const Any& x, sal_Int32 sqlType, sal_Int32 scale ) throw(SQLException, RuntimeException, std::exception)
552 : {
553 : (void) parameterIndex;
554 : (void) x;
555 : (void) sqlType;
556 : (void) scale;
557 0 : checkDisposed(OStatementCommonBase_Base::rBHelper.bDisposed);
558 0 : ::osl::MutexGuard aGuard( m_aMutex );
559 :
560 0 : }
561 :
562 :
563 0 : void SAL_CALL OPreparedStatement::setObjectNull( sal_Int32 parameterIndex, sal_Int32 sqlType, const ::rtl::OUString& typeName ) throw(SQLException, RuntimeException, std::exception)
564 : {
565 : (void) parameterIndex;
566 : (void) sqlType;
567 : (void) typeName;
568 0 : ::osl::MutexGuard aGuard( m_aMutex );
569 0 : checkDisposed(OStatementCommonBase_Base::rBHelper.bDisposed);
570 :
571 0 : }
572 :
573 :
574 0 : void SAL_CALL OPreparedStatement::setObject( sal_Int32 parameterIndex, const Any& x ) throw(SQLException, RuntimeException, std::exception)
575 : {
576 : (void) parameterIndex;
577 : (void) x;
578 0 : ::osl::MutexGuard aGuard( m_aMutex );
579 0 : checkDisposed(OStatementCommonBase_Base::rBHelper.bDisposed);
580 :
581 0 : }
582 :
583 0 : void SAL_CALL OPreparedStatement::setBytes(sal_Int32 nParameterIndex,
584 : const Sequence< sal_Int8 >& xBytes)
585 : throw (SQLException, RuntimeException, std::exception)
586 : {
587 0 : ::osl::MutexGuard aGuard(m_aMutex);
588 0 : checkDisposed(OStatementCommonBase_Base::rBHelper.bDisposed);
589 :
590 0 : isc_blob_handle aBlobHandle = 0;
591 : ISC_QUAD aBlobId;
592 :
593 0 : openBlobForWriting(aBlobHandle, aBlobId);
594 :
595 : // Max segment size is 2^16 == SAL_MAX_UINT16
596 0 : sal_uInt64 nDataWritten = 0;
597 0 : ISC_STATUS aErr = 0;
598 0 : while (xBytes.getLength() - nDataWritten > 0)
599 : {
600 0 : sal_uInt64 nDataRemaining = xBytes.getLength() - nDataWritten;
601 0 : sal_uInt16 nWriteSize = (nDataRemaining > SAL_MAX_UINT16) ? SAL_MAX_UINT16 : nDataRemaining;
602 : aErr = isc_put_segment(m_statusVector,
603 : &aBlobHandle,
604 : nWriteSize,
605 0 : (const char*) xBytes.getConstArray() + nDataWritten);
606 0 : nDataWritten += nWriteSize;
607 :
608 0 : if (aErr)
609 0 : break;
610 : }
611 :
612 : // We need to make sure we close the Blob even if their are errors, hence evaluate
613 : // errors after closing.
614 0 : closeBlobAfterWriting(aBlobHandle);
615 :
616 0 : if (aErr)
617 : {
618 : evaluateStatusVector(m_statusVector,
619 : "isc_put_segment failed",
620 0 : *this);
621 : assert(false);
622 : }
623 :
624 0 : setValue< ISC_QUAD >(nParameterIndex, aBlobId, SQL_BLOB);
625 0 : }
626 :
627 :
628 :
629 0 : void SAL_CALL OPreparedStatement::setCharacterStream( sal_Int32 parameterIndex, const Reference< ::com::sun::star::io::XInputStream >& x, sal_Int32 length ) throw(SQLException, RuntimeException, std::exception)
630 : {
631 : (void) parameterIndex;
632 : (void) x;
633 : (void) length;
634 0 : ::osl::MutexGuard aGuard( m_aMutex );
635 0 : checkDisposed(OStatementCommonBase_Base::rBHelper.bDisposed);
636 :
637 0 : }
638 :
639 :
640 0 : void SAL_CALL OPreparedStatement::setBinaryStream( sal_Int32 parameterIndex, const Reference< ::com::sun::star::io::XInputStream >& x, sal_Int32 length ) throw(SQLException, RuntimeException, std::exception)
641 : {
642 : (void) parameterIndex;
643 : (void) x;
644 : (void) length;
645 0 : ::osl::MutexGuard aGuard( m_aMutex );
646 0 : checkDisposed(OStatementCommonBase_Base::rBHelper.bDisposed);
647 :
648 0 : }
649 :
650 :
651 0 : void SAL_CALL OPreparedStatement::clearParameters( ) throw(SQLException, RuntimeException, std::exception)
652 : {
653 0 : }
654 :
655 : // ---- Batch methods -- unsupported -----------------------------------------
656 0 : void SAL_CALL OPreparedStatement::clearBatch()
657 : throw(SQLException, RuntimeException, std::exception)
658 : {
659 : // Unsupported
660 0 : }
661 :
662 0 : void SAL_CALL OPreparedStatement::addBatch()
663 : throw(SQLException, RuntimeException, std::exception)
664 : {
665 : // Unsupported by firebird
666 0 : }
667 :
668 0 : Sequence< sal_Int32 > SAL_CALL OPreparedStatement::executeBatch()
669 : throw(SQLException, RuntimeException, std::exception)
670 : {
671 : // Unsupported by firebird
672 0 : return Sequence< sal_Int32 >();
673 : }
674 :
675 0 : void OPreparedStatement::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any& rValue) throw (Exception, std::exception)
676 : {
677 0 : switch(nHandle)
678 : {
679 : case PROPERTY_ID_RESULTSETCONCURRENCY:
680 0 : break;
681 : case PROPERTY_ID_RESULTSETTYPE:
682 0 : break;
683 : case PROPERTY_ID_FETCHDIRECTION:
684 0 : break;
685 : case PROPERTY_ID_USEBOOKMARKS:
686 0 : break;
687 : default:
688 0 : OStatementCommonBase::setFastPropertyValue_NoBroadcast(nHandle,rValue);
689 : }
690 0 : }
691 :
692 0 : void OPreparedStatement::checkParameterIndex(sal_Int32 nParameterIndex)
693 : throw(SQLException, RuntimeException)
694 : {
695 0 : ensurePrepared();
696 0 : if ((nParameterIndex == 0) || (nParameterIndex > m_pInSqlda->sqld))
697 : {
698 : ::dbtools::throwSQLException(
699 0 : "No column " + OUString::number(nParameterIndex),
700 : ::dbtools::SQL_COLUMN_NOT_FOUND,
701 0 : *this);
702 : }
703 0 : }
704 :
705 0 : void OPreparedStatement::setParameterNull(sal_Int32 nParameterIndex,
706 : bool bSetNull)
707 : {
708 0 : XSQLVAR* pVar = m_pInSqlda->sqlvar + (nParameterIndex - 1);
709 0 : if (pVar->sqltype & 1)
710 : {
711 0 : if (bSetNull)
712 0 : *pVar->sqlind = -1;
713 : else
714 0 : *pVar->sqlind = 0;
715 : }
716 0 : }
717 :
718 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|