From adc10258c7ab263ed8f7f44de3119aab6ea00187 Mon Sep 17 00:00:00 2001 From: Tamas Bunth Date: Sat, 1 Dec 2018 21:51:45 +0100 Subject: mysql_jdbc: test simultaneously opened result sets MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I413fa17ee0fc264526133eca12ee747d40d6ac6a Reviewed-on: https://gerrit.libreoffice.org/64412 Tested-by: Jenkins Reviewed-by: Tamás Bunth --- connectivity/qa/connectivity/mysql/mysql.cxx | 51 ++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'connectivity/qa') diff --git a/connectivity/qa/connectivity/mysql/mysql.cxx b/connectivity/qa/connectivity/mysql/mysql.cxx index 16172439df0f..ee502ed286b7 100644 --- a/connectivity/qa/connectivity/mysql/mysql.cxx +++ b/connectivity/qa/connectivity/mysql/mysql.cxx @@ -40,18 +40,35 @@ public: { } virtual void setUp() override; + virtual void tearDown() override; void testDBConnection(); void testCreateAndDropTable(); void testIntegerInsertAndQuery(); void testDBPositionChange(); + void testMultipleResultsets(); CPPUNIT_TEST_SUITE(MysqlTestDriver); CPPUNIT_TEST(testDBConnection); CPPUNIT_TEST(testCreateAndDropTable); CPPUNIT_TEST(testIntegerInsertAndQuery); + CPPUNIT_TEST(testMultipleResultsets); CPPUNIT_TEST_SUITE_END(); }; +void MysqlTestDriver::tearDown() +{ + Reference xConnection = m_xDriver->connect(m_sUrl, m_infos); + if (!xConnection.is()) + { + CPPUNIT_ASSERT_MESSAGE("cannot connect to data source!", xConnection.is()); + } + uno::Reference xStatement = xConnection->createStatement(); + CPPUNIT_ASSERT(xStatement.is()); + xStatement->executeUpdate("DROP TABLE IF EXISTS myTestTable"); + xStatement->executeUpdate("DROP TABLE IF EXISTS otherTable"); + test::BootstrapFixture::tearDown(); +} + void MysqlTestDriver::setUp() { test::BootstrapFixture::setUp(); @@ -236,6 +253,40 @@ void MysqlTestDriver::testDBPositionChange() CPPUNIT_ASSERT_EQUAL(0, nUpdateCount); // it's a DDL statement } +void MysqlTestDriver::testMultipleResultsets() +{ + Reference xConnection = m_xDriver->connect(m_sUrl, m_infos); + CPPUNIT_ASSERT(xConnection.is()); + Reference xStatement = xConnection->createStatement(); + CPPUNIT_ASSERT(xStatement.is()); + // create two tables + xStatement->executeUpdate("DROP TABLE IF EXISTS myTestTable"); + xStatement->executeUpdate("DROP TABLE IF EXISTS otherTable"); + xStatement->executeUpdate("CREATE TABLE myTestTable (id INTEGER PRIMARY KEY)"); + xStatement->executeUpdate("INSERT INTO myTestTable VALUES (1)"); + xStatement->executeUpdate("CREATE TABLE otherTable (id INTEGER PRIMARY KEY)"); + xStatement->executeUpdate("INSERT INTO otherTable VALUES (2)"); + + // create first result set + Reference xResultSet = xStatement->executeQuery("SELECT id from myTestTable"); + CPPUNIT_ASSERT_MESSAGE("result set cannot be instantiated after query", xResultSet.is()); + // use it + xResultSet->next(); + Reference xRowFirst(xResultSet, UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(1l, xRowFirst->getLong(1)); + // create second result set + Reference xResultSet2 = xStatement->executeQuery("SELECT id from otherTable"); + // use second result set + xResultSet2->next(); + Reference xRowSecond(xResultSet2, UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(2l, xRowSecond->getLong(1)); + // now use the first result set again + CPPUNIT_ASSERT_EQUAL(1l, xRowFirst->getLong(1)); + + xStatement->executeUpdate("DROP TABLE myTestTable"); + xStatement->executeUpdate("DROP TABLE otherTable"); +} + CPPUNIT_TEST_SUITE_REGISTRATION(MysqlTestDriver); CPPUNIT_PLUGIN_IMPLEMENT(); -- cgit