diff options
author | Tamas Bunth <tamas.bunth@collabora.co.uk> | 2018-03-04 17:30:13 +0100 |
---|---|---|
committer | Tamás Bunth <btomi96@gmail.com> | 2018-03-07 11:31:12 +0100 |
commit | c25b884d5493422e126a7f4e52008cebb073ec7a (patch) | |
tree | 6e3bf1749b3286ddcee32e11bda57a81e112bd7c /connectivity | |
parent | 70306e5a3e7f9f999b06d5c7c3f9118dbb51ae54 (diff) |
Firebird: allow setting BINARY fix and VARBINARY
Allow setting BINARY (fix) and VARBINARY types in method setBytes.
Change-Id: I6c8cfc5aff6e1240eadd6b061d629586a25b71c3
Reviewed-on: https://gerrit.libreoffice.org/50735
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Tamás Bunth <btomi96@gmail.com>
Diffstat (limited to 'connectivity')
-rw-r--r-- | connectivity/source/drivers/firebird/PreparedStatement.cxx | 91 |
1 files changed, 62 insertions, 29 deletions
diff --git a/connectivity/source/drivers/firebird/PreparedStatement.cxx b/connectivity/source/drivers/firebird/PreparedStatement.cxx index 9d9a6853e1fa..2f48c63c746e 100644 --- a/connectivity/source/drivers/firebird/PreparedStatement.cxx +++ b/connectivity/source/drivers/firebird/PreparedStatement.cxx @@ -787,45 +787,78 @@ void SAL_CALL OPreparedStatement::setBytes(sal_Int32 nParameterIndex, checkDisposed(OStatementCommonBase_Base::rBHelper.bDisposed); checkParameterIndex(nParameterIndex); + XSQLVAR* pVar = m_pInSqlda->sqlvar + (nParameterIndex - 1); + int dType = (pVar->sqltype & ~1); // drop flag bit for now + + if( dType == SQL_BLOB ) + { #if SAL_TYPES_SIZEOFPOINTER == 8 - isc_blob_handle aBlobHandle = 0; + isc_blob_handle aBlobHandle = 0; #else - isc_blob_handle aBlobHandle = nullptr; + isc_blob_handle aBlobHandle = nullptr; #endif - ISC_QUAD aBlobId; + ISC_QUAD aBlobId; - openBlobForWriting(aBlobHandle, aBlobId); + openBlobForWriting(aBlobHandle, aBlobId); - // Max segment size is 2^16 == SAL_MAX_UINT16 - sal_uInt64 nDataWritten = 0; - ISC_STATUS aErr = 0; - while (xBytes.getLength() - nDataWritten > 0) - { - sal_uInt64 nDataRemaining = xBytes.getLength() - nDataWritten; - sal_uInt16 nWriteSize = std::min<sal_uInt64>(nDataRemaining, SAL_MAX_UINT16); - aErr = isc_put_segment(m_statusVector, - &aBlobHandle, - nWriteSize, - reinterpret_cast<const char*>(xBytes.getConstArray()) + nDataWritten); - nDataWritten += nWriteSize; + // Max segment size is 2^16 == SAL_MAX_UINT16 + sal_uInt64 nDataWritten = 0; + ISC_STATUS aErr = 0; + while (xBytes.getLength() - nDataWritten > 0) + { + sal_uInt64 nDataRemaining = xBytes.getLength() - nDataWritten; + sal_uInt16 nWriteSize = std::min<sal_uInt64>(nDataRemaining, SAL_MAX_UINT16); + aErr = isc_put_segment(m_statusVector, + &aBlobHandle, + nWriteSize, + reinterpret_cast<const char*>(xBytes.getConstArray()) + nDataWritten); + nDataWritten += nWriteSize; + + if (aErr) + break; + } - if (aErr) - break; - } + // We need to make sure we close the Blob even if their are errors, hence evaluate + // errors after closing. + closeBlobAfterWriting(aBlobHandle); - // We need to make sure we close the Blob even if their are errors, hence evaluate - // errors after closing. - closeBlobAfterWriting(aBlobHandle); + if (aErr) + { + evaluateStatusVector(m_statusVector, + "isc_put_segment failed", + *this); + assert(false); + } - if (aErr) + setValue< ISC_QUAD >(nParameterIndex, aBlobId, SQL_BLOB); + } + else if( dType == SQL_VARYING ) { - evaluateStatusVector(m_statusVector, - "isc_put_segment failed", - *this); - assert(false); + const sal_Int32 nMaxSize = 0xFFFF; + Sequence<sal_Int8> xBytesCopy(xBytes); + // First 2 bytes indicate string size + if (xBytesCopy.getLength() > nMaxSize) + { + xBytesCopy.realloc( nMaxSize ); + } + const short nSize = xBytesCopy.getLength(); + memcpy(pVar->sqldata, &nSize, 2); + // Actual data + memcpy(pVar->sqldata + 2, xBytesCopy.getConstArray(), nSize); + } + else if( dType == SQL_TEXT ) + { + memcpy(pVar->sqldata, xBytes.getConstArray(), xBytes.getLength() ); + // Fill remainder with spaces + memset(pVar->sqldata + xBytes.getLength(), 0, pVar->sqllen - xBytes.getLength()); + } + else + { + ::dbtools::throwSQLException( + "Incorrect type for setBytes", + ::dbtools::StandardSQLState::INVALID_SQL_DATA_TYPE, + *this); } - - setValue< ISC_QUAD >(nParameterIndex, aBlobId, SQL_BLOB); } |