[Libreoffice-commits] core.git: Branch 'libreoffice-4-0' - connectivity/source

Lionel Elie Mamane lionel at mamane.lu
Tue Sep 3 04:59:33 PDT 2013


 connectivity/source/drivers/odbcbase/OResultSet.cxx |   60 +++++++++++++-------
 1 file changed, 39 insertions(+), 21 deletions(-)

New commits:
commit eb0aef67c76e23e77be12deda0acfb2475368fa2
Author: Lionel Elie Mamane <lionel at mamane.lu>
Date:   Tue Aug 27 17:59:42 2013 +0200

    fdo#68315 odbc update *reads* a bookmark, not *writes* a bookmark
    
    This code was completely inverted. The row update operation
    *reads* a bookmark (that is, what row to update), not *writes*
    a bookmark.
    
    So we were passing an empty bookmark, and thus the update was failing
    because we were refering to a non-existent row.
    
    Change-Id: I676b1a7727a88e13a3e465bd96cbbaf18dad2fa6
    Reviewed-on: https://gerrit.libreoffice.org/5649
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/connectivity/source/drivers/odbcbase/OResultSet.cxx b/connectivity/source/drivers/odbcbase/OResultSet.cxx
index 29c834e..eb6c328 100644
--- a/connectivity/source/drivers/odbcbase/OResultSet.cxx
+++ b/connectivity/source/drivers/odbcbase/OResultSet.cxx
@@ -937,29 +937,47 @@ void SAL_CALL OResultSet::updateRow(  ) throw(SQLException, RuntimeException)
 
     SQLRETURN nRet;
 
-    sal_Bool bPositionByBookmark = ( NULL != getOdbcFunction( ODBC3SQLBulkOperations ) );
-    Sequence<sal_Int8> aBookmark(nMaxBookmarkLen);
-    if ( bPositionByBookmark )
+    try
     {
-        SQLLEN nRealLen = 0;
-        nRet = N3SQLBindCol(m_aStatementHandle,
-                            0,
-                            SQL_C_VARBOOKMARK,
-                            aBookmark.getArray(),
-                            aBookmark.getLength(),
-                            &nRealLen
-                            );
-        fillNeededData(nRet = N3SQLBulkOperations(m_aStatementHandle, SQL_UPDATE_BY_BOOKMARK));
-        aBookmark.realloc(nRealLen);
-        m_aRow[0]=aBookmark;
-        m_aRow[0].setBound(true);
+        sal_Bool bPositionByBookmark = ( NULL != getOdbcFunction( ODBC3SQLBulkOperations ) );
+        if ( bPositionByBookmark )
+        {
+            getBookmark();
+            assert(m_aRow[0].isBound());
+            Sequence<sal_Int8> aBookmark(m_aRow[0].getSequence());
+            SQLLEN nRealLen = aBookmark.getLength();
+            nRet = N3SQLBindCol(m_aStatementHandle,
+                                0,
+                                SQL_C_VARBOOKMARK,
+                                aBookmark.getArray(),
+                                aBookmark.getLength(),
+                                &nRealLen
+                                );
+            OTools::ThrowException(m_pStatement->getOwnConnection(),nRet,m_aStatementHandle,SQL_HANDLE_STMT,*this);
+            fillNeededData(nRet = N3SQLBulkOperations(m_aStatementHandle, SQL_UPDATE_BY_BOOKMARK));
+            // the driver should not have touched this
+            // (neither the contents of aBookmark FWIW)
+            assert(nRealLen == aBookmark.getLength());
+        }
+        else
+        {
+            fillNeededData(nRet = N3SQLSetPos(m_aStatementHandle,1,SQL_UPDATE,SQL_LOCK_NO_CHANGE));
+        }
+        OTools::ThrowException(m_pStatement->getOwnConnection(),nRet,m_aStatementHandle,SQL_HANDLE_STMT,*this);
+        // unbind all columns so we can fetch all columns again with SQLGetData
+        // (and also so that our buffers don't clobber anything, and
+        //  so that a subsequent fetch does not overwrite m_aRow[0])
+        invalidateCache();
+        nRet = unbind();
+        OSL_ENSURE(nRet == SQL_SUCCESS,"ODBC insert could not unbind the columns after success");
+    }
+    catch(...)
+    {
+        // unbind all columns so that a subsequent fetch does not overwrite m_aRow[0]
+        nRet = unbind();
+        OSL_ENSURE(nRet == SQL_SUCCESS,"ODBC insert could not unbind the columns after failure");
+        throw;
     }
-    else
-        fillNeededData(nRet = N3SQLSetPos(m_aStatementHandle,1,SQL_UPDATE,SQL_LOCK_NO_CHANGE));
-    OTools::ThrowException(m_pStatement->getOwnConnection(),nRet,m_aStatementHandle,SQL_HANDLE_STMT,*this);
-    // now unbind all columns so we can fetch all columns again with SQLGetData
-    nRet = unbind();
-    OSL_ENSURE(nRet == SQL_SUCCESS,"Could not unbind the columns!");
 }
 // -------------------------------------------------------------------------
 void SAL_CALL OResultSet::deleteRow(  ) throw(SQLException, RuntimeException)


More information about the Libreoffice-commits mailing list