summaryrefslogtreecommitdiff
path: root/connectivity/qa
diff options
context:
space:
mode:
authorTamas Bunth <tamas.bunth@collabora.co.uk>2019-07-29 13:27:38 +0200
committerTamás Bunth <btomi96@gmail.com>2019-07-29 22:33:38 +0200
commit41d3be4a48ea2abe019cd4f9b51bef703a2dc454 (patch)
tree1be3709a7209b4f24a73f489ade020091918f835 /connectivity/qa
parentd2bb93e299f42e2ab4ea8940fb4dc5da01a386b6 (diff)
mysqlc: Fix query of cursor position in result set
Fix queries like "IsAfterLast" in result sets of prepared statements in the mysql driver. Cursor position is stored in the driver, since the mysql C driver does not support the query of the cursor position. The cursor position works the following way: - 0 means the cursor is on "BeforeFirst". In that state calling of getXXX() methods is user error. - 1 means the first row is already fetched. - n means the last fow is fetched, where n is the total number of rows in the result set. - Everything bigger than n is "AfterLast" Change-Id: I131f2042606897019cc0f868dbc4151faf4850ac Reviewed-on: https://gerrit.libreoffice.org/76549 Tested-by: Jenkins Reviewed-by: Tamás Bunth <btomi96@gmail.com>
Diffstat (limited to 'connectivity/qa')
-rw-r--r--connectivity/qa/connectivity/mysql/mysql.cxx41
1 files changed, 41 insertions, 0 deletions
diff --git a/connectivity/qa/connectivity/mysql/mysql.cxx b/connectivity/qa/connectivity/mysql/mysql.cxx
index 3e48ce5b3750..24af725b0110 100644
--- a/connectivity/qa/connectivity/mysql/mysql.cxx
+++ b/connectivity/qa/connectivity/mysql/mysql.cxx
@@ -54,6 +54,7 @@ public:
void testDBMetaData();
void testTimestampField();
void testNumericConversionPrepared();
+ void testPreparedStmtIsAfterLast();
CPPUNIT_TEST_SUITE(MysqlTestDriver);
CPPUNIT_TEST(testDBConnection);
@@ -63,6 +64,7 @@ public:
CPPUNIT_TEST(testDBMetaData);
CPPUNIT_TEST(testTimestampField);
CPPUNIT_TEST(testNumericConversionPrepared);
+ CPPUNIT_TEST(testPreparedStmtIsAfterLast);
CPPUNIT_TEST_SUITE_END();
};
@@ -405,6 +407,45 @@ void MysqlTestDriver::testNumericConversionPrepared()
xStatement->executeUpdate("DROP TABLE myTestTable");
}
+/**
+ * Test cursor positioning method isAfterLast in case of using prepared
+ * statement.
+ */
+void MysqlTestDriver::testPreparedStmtIsAfterLast()
+{
+ Reference<XConnection> xConnection = m_xDriver->connect(m_sUrl, m_infos);
+ if (!xConnection.is())
+ CPPUNIT_ASSERT_MESSAGE("cannot connect to data source!", xConnection.is());
+ uno::Reference<XStatement> xStatement = xConnection->createStatement();
+ CPPUNIT_ASSERT(xStatement.is());
+ xStatement->executeUpdate("DROP TABLE IF EXISTS myTestTable");
+
+ // create test table
+ xStatement->executeUpdate("CREATE TABLE myTestTable (id INTEGER PRIMARY KEY)");
+ Reference<XPreparedStatement> xPrepared
+ = xConnection->prepareStatement(OUString{ "INSERT INTO myTestTable VALUES (?)" });
+ Reference<XParameters> xParams(xPrepared, UNO_QUERY);
+ constexpr int ROW_COUNT = 6;
+ for (int i = 0; i < ROW_COUNT; ++i)
+ {
+ xParams->setShort(1, i);
+ xPrepared->executeUpdate();
+ }
+
+ // query test table
+ xPrepared = xConnection->prepareStatement("SELECT id from myTestTable where id = 3");
+ Reference<XResultSet> xResultSet = xPrepared->executeQuery();
+
+ // There should be exactly one row, therefore IsAfterLast is false at first.
+ xResultSet->next();
+ CPPUNIT_ASSERT(!xResultSet->isAfterLast());
+
+ // attempt to fetch more data
+ bool hasData = xResultSet->next();
+ CPPUNIT_ASSERT(!hasData); // now we are on "AfterLast"
+ CPPUNIT_ASSERT(xResultSet->isAfterLast());
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(MysqlTestDriver);
CPPUNIT_PLUGIN_IMPLEMENT();