Kaydet (Commit) c25b884d authored tarafından Tamas Bunth's avatar Tamas Bunth Kaydeden (comit) Tamás Bunth

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/50735Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarTamás Bunth <btomi96@gmail.com>
üst 70306e5a
...@@ -787,45 +787,78 @@ void SAL_CALL OPreparedStatement::setBytes(sal_Int32 nParameterIndex, ...@@ -787,45 +787,78 @@ void SAL_CALL OPreparedStatement::setBytes(sal_Int32 nParameterIndex,
checkDisposed(OStatementCommonBase_Base::rBHelper.bDisposed); checkDisposed(OStatementCommonBase_Base::rBHelper.bDisposed);
checkParameterIndex(nParameterIndex); 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 #if SAL_TYPES_SIZEOFPOINTER == 8
isc_blob_handle aBlobHandle = 0; isc_blob_handle aBlobHandle = 0;
#else #else
isc_blob_handle aBlobHandle = nullptr; isc_blob_handle aBlobHandle = nullptr;
#endif #endif
ISC_QUAD aBlobId; ISC_QUAD aBlobId;
openBlobForWriting(aBlobHandle, aBlobId); openBlobForWriting(aBlobHandle, aBlobId);
// Max segment size is 2^16 == SAL_MAX_UINT16 // Max segment size is 2^16 == SAL_MAX_UINT16
sal_uInt64 nDataWritten = 0; sal_uInt64 nDataWritten = 0;
ISC_STATUS aErr = 0; ISC_STATUS aErr = 0;
while (xBytes.getLength() - nDataWritten > 0) while (xBytes.getLength() - nDataWritten > 0)
{ {
sal_uInt64 nDataRemaining = xBytes.getLength() - nDataWritten; sal_uInt64 nDataRemaining = xBytes.getLength() - nDataWritten;
sal_uInt16 nWriteSize = std::min<sal_uInt64>(nDataRemaining, SAL_MAX_UINT16); sal_uInt16 nWriteSize = std::min<sal_uInt64>(nDataRemaining, SAL_MAX_UINT16);
aErr = isc_put_segment(m_statusVector, aErr = isc_put_segment(m_statusVector,
&aBlobHandle, &aBlobHandle,
nWriteSize, nWriteSize,
reinterpret_cast<const char*>(xBytes.getConstArray()) + nDataWritten); reinterpret_cast<const char*>(xBytes.getConstArray()) + nDataWritten);
nDataWritten += nWriteSize; nDataWritten += nWriteSize;
if (aErr)
break;
}
if (aErr) // We need to make sure we close the Blob even if their are errors, hence evaluate
break; // errors after closing.
} closeBlobAfterWriting(aBlobHandle);
// We need to make sure we close the Blob even if their are errors, hence evaluate if (aErr)
// errors after closing. {
closeBlobAfterWriting(aBlobHandle); 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, const sal_Int32 nMaxSize = 0xFFFF;
"isc_put_segment failed", Sequence<sal_Int8> xBytesCopy(xBytes);
*this); // First 2 bytes indicate string size
assert(false); 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);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment