summaryrefslogtreecommitdiff
path: root/connectivity
diff options
context:
space:
mode:
authorLionel Elie Mamane <lionel@mamane.lu>2013-08-27 17:59:42 +0200
committerCaolán McNamara <caolanm@redhat.com>2013-09-03 11:59:05 +0000
commiteb0aef67c76e23e77be12deda0acfb2475368fa2 (patch)
treeaf08935b85d0ff5898a142d4b63e3d403618a235 /connectivity
parente57bb359ae4124f2603b9ab44d1534e4489e914a (diff)
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@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'connectivity')
-rw-r--r--connectivity/source/drivers/odbcbase/OResultSet.cxx60
1 files changed, 39 insertions, 21 deletions
diff --git a/connectivity/source/drivers/odbcbase/OResultSet.cxx b/connectivity/source/drivers/odbcbase/OResultSet.cxx
index 29c834e279df..eb6c32894824 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)