diff options
author | Tamas Bunth <tamas.bunth@collabora.co.uk> | 2018-10-30 18:49:46 +0100 |
---|---|---|
committer | Tamás Bunth <btomi96@gmail.com> | 2018-11-05 10:06:03 +0100 |
commit | 0c6da44c9249e7b9355c0efd9a60004701867275 (patch) | |
tree | c23bb2a2421c3e1ffecc31e08880bb5588efbdcd /connectivity/qa | |
parent | f2cd1c3c7cce2699d1341f726fc90cf30b52612c (diff) |
mysqlc: allow multiple open statements
Change-Id: I07e57ea7d9e6af1c7543483b1ab54a0b8c5be2d5
Reviewed-on: https://gerrit.libreoffice.org/62640
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Reviewed-by: Tamás Bunth <btomi96@gmail.com>
Diffstat (limited to 'connectivity/qa')
-rw-r--r-- | connectivity/qa/connectivity/mysql/mysql.cxx | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/connectivity/qa/connectivity/mysql/mysql.cxx b/connectivity/qa/connectivity/mysql/mysql.cxx index f5057dce1519..f78ea2ea57e5 100644 --- a/connectivity/qa/connectivity/mysql/mysql.cxx +++ b/connectivity/qa/connectivity/mysql/mysql.cxx @@ -43,6 +43,7 @@ public: void testDBConnection(); void testCreateAndDropTable(); void testIntegerInsertAndQuery(); + void testDBPositionChange(); CPPUNIT_TEST_SUITE(MysqlTestDriver); CPPUNIT_TEST(testDBConnection); @@ -175,6 +176,53 @@ void MysqlTestDriver::testIntegerInsertAndQuery() CPPUNIT_ASSERT_EQUAL(0, nUpdateCount); // it's a DDL statement } +void MysqlTestDriver::testDBPositionChange() +{ + Reference<XConnection> xConnection = m_xDriver->connect(m_sUrl, m_infos); + if (!xConnection.is()) + { + CPPUNIT_ASSERT_MESSAGE("cannot connect to data source!", xConnection.is()); + } + + Reference<XStatement> xStatement = xConnection->createStatement(); + CPPUNIT_ASSERT(xStatement.is()); + + auto nUpdateCount + = xStatement->executeUpdate("CREATE TABLE myTestTable (id INTEGER PRIMARY KEY)"); + CPPUNIT_ASSERT_EQUAL(0, nUpdateCount); // it's a DDL statement + Reference<XPreparedStatement> xPrepared + = xConnection->prepareStatement(OUString{ "INSERT INTO myTestTable VALUES (?)" }); + Reference<XParameters> xParams(xPrepared, UNO_QUERY); + constexpr int ROW_COUNT = 3; + for (int i = 1; i <= ROW_COUNT; ++i) + { + xParams->setLong(1, i); // first and only column + nUpdateCount = xPrepared->executeUpdate(); + CPPUNIT_ASSERT_EQUAL(1, nUpdateCount); // one row is inserted at a time + } + Reference<XResultSet> xResultSet = xStatement->executeQuery("SELECT id from myTestTable"); + CPPUNIT_ASSERT_MESSAGE("result set cannot be instantiated after query", xResultSet.is()); + Reference<XRow> xRow(xResultSet, UNO_QUERY); + CPPUNIT_ASSERT_MESSAGE("cannot extract row from result set!", xRow.is()); + + xResultSet->afterLast(); + CPPUNIT_ASSERT_EQUAL(ROW_COUNT + 1, xResultSet->getRow()); + xResultSet->last(); + CPPUNIT_ASSERT_EQUAL(ROW_COUNT, nUpdateCount); + CPPUNIT_ASSERT_EQUAL(ROW_COUNT, xResultSet->getRow()); + bool successPrevios = xResultSet->previous(); + CPPUNIT_ASSERT(successPrevios); + CPPUNIT_ASSERT_EQUAL(ROW_COUNT - 1, nUpdateCount); + xResultSet->beforeFirst(); + xResultSet->next(); + CPPUNIT_ASSERT_EQUAL(1, xResultSet->getRow()); + xResultSet->first(); + CPPUNIT_ASSERT_EQUAL(1, xResultSet->getRow()); + + nUpdateCount = xStatement->executeUpdate("DROP TABLE myTestTable"); + CPPUNIT_ASSERT_EQUAL(0, nUpdateCount); // it's a DDL statement +} + CPPUNIT_TEST_SUITE_REGISTRATION(MysqlTestDriver); CPPUNIT_PLUGIN_IMPLEMENT(); |