[Libreoffice-commits] core.git: connectivity/source

Tamas Bunth tamas.bunth at collabora.co.uk
Wed Mar 7 10:31:39 UTC 2018


 connectivity/source/drivers/firebird/PreparedStatement.cxx |   91 ++++++++-----
 1 file changed, 62 insertions(+), 29 deletions(-)

New commits:
commit c25b884d5493422e126a7f4e52008cebb073ec7a
Author: Tamas Bunth <tamas.bunth at collabora.co.uk>
Date:   Sun Mar 4 17:30:13 2018 +0100

    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 at libreoffice.org>
    Reviewed-by: Tamás Bunth <btomi96 at gmail.com>

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);
 }
 
 


More information about the Libreoffice-commits mailing list