summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTamas Bunth <tamas.bunth@collabora.co.uk>2018-11-23 18:31:37 +0100
committerAndras Timar <andras.timar@collabora.com>2018-11-26 11:44:19 +0100
commitd1beae8257a2b1124db2df3c6893fc3c2608ace0 (patch)
tree05b97030cb3f78b8c7bac388a33e2a15d55446d8
parent82d4b092e127f2222a5deaf4f6606d5ebae882dc (diff)
mysqlc: next() should move cursor from Last
XResultSet::next() should move cursor when called while cursor is on the last position. It is not documented, but older versions of the mysqlc extension are implemented that way. The cursor goes to the so called afterlast position. Even so, the next() call on the last position should return false. Change-Id: I0fd145c920077151364a6a8c12e05290496b99c8 Reviewed-on: https://gerrit.libreoffice.org/63895 Tested-by: Jenkins Reviewed-by: Tamás Bunth <btomi96@gmail.com> Reviewed-on: https://gerrit.libreoffice.org/64017 Reviewed-by: Andras Timar <andras.timar@collabora.com> Tested-by: Andras Timar <andras.timar@collabora.com>
-rw-r--r--connectivity/qa/connectivity/mysql/mysql.cxx11
-rw-r--r--connectivity/source/drivers/mysqlc/mysqlc_resultset.cxx8
2 files changed, 16 insertions, 3 deletions
diff --git a/connectivity/qa/connectivity/mysql/mysql.cxx b/connectivity/qa/connectivity/mysql/mysql.cxx
index 8f2f664056c4..f5e878590363 100644
--- a/connectivity/qa/connectivity/mysql/mysql.cxx
+++ b/connectivity/qa/connectivity/mysql/mysql.cxx
@@ -173,9 +173,16 @@ void MysqlTestDriver::testIntegerInsertAndQuery()
CPPUNIT_ASSERT_MESSAGE("not enough result after query", hasRow);
CPPUNIT_ASSERT_EQUAL(i, xRow->getLong(1)); // first and only column
}
- bool hasRow = xResultSet->next();
- // no more rows
+ CPPUNIT_ASSERT_MESSAGE("Cursor is not on last position.",
+ xResultSet->isLast()); // cursor is on last position
+ CPPUNIT_ASSERT_EQUAL(ROW_COUNT, xResultSet->getRow()); // which is the last position
+
+ bool hasRow = xResultSet->next(); // go to afterlast
+ // no more rows, next should return false
CPPUNIT_ASSERT_MESSAGE("next returns true after last row", !hasRow);
+ // cursor should be in afterlast position
+ CPPUNIT_ASSERT_EQUAL(ROW_COUNT + 1, xResultSet->getRow());
+ CPPUNIT_ASSERT_MESSAGE("Cursor is not on after-last position.", xResultSet->isAfterLast());
nUpdateCount = xStatement->executeUpdate("DROP TABLE myTestTable");
CPPUNIT_ASSERT_EQUAL(0, nUpdateCount); // it's a DDL statement
diff --git a/connectivity/source/drivers/mysqlc/mysqlc_resultset.cxx b/connectivity/source/drivers/mysqlc/mysqlc_resultset.cxx
index 50ab0be3af16..392a037b3ed3 100644
--- a/connectivity/source/drivers/mysqlc/mysqlc_resultset.cxx
+++ b/connectivity/source/drivers/mysqlc/mysqlc_resultset.cxx
@@ -693,8 +693,14 @@ sal_Bool SAL_CALL OResultSet::next()
MutexGuard aGuard(m_aMutex);
checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
ensureResultFetched();
- if (m_nRowPosition + 1 >= m_nRowCount)
+ if (m_nRowPosition + 1 > m_nRowCount) // afterlast
return false;
+ if (m_nRowPosition + 1 == m_nRowCount) // last
+ {
+ // return false but take it to afterlast anyway
+ ++m_nRowPosition;
+ return false;
+ }
++m_nRowPosition;
return true;
}