summaryrefslogtreecommitdiffstats
path: root/connectivity/qa
diff options
context:
space:
mode:
authorTamas Bunth <tamas.bunth@collabora.co.uk>2018-12-29 15:22:56 +0100
committerTamás Bunth <btomi96@gmail.com>2019-01-04 17:37:26 +0100
commitee33372f6406d7352bc7e19914ec5fb0059c4e01 (patch)
tree0ae19e7c40c58dcd925b5ed59241c121446561f7 /connectivity/qa
parenttdf#122459 Qt5 IM underline pre-edit (diff)
downloadcore-ee33372f6406d7352bc7e19914ec5fb0059c4e01.tar.gz
core-ee33372f6406d7352bc7e19914ec5fb0059c4e01.zip
mysqlc: Fix result set metadata related issue
In order to allow fetching result of multiple result sets at time same time, all the data is fetched and copied on demand from the mysql result set. The mysql result set (MYSQL_RES) is freed afterwards. That means we need a copy of the meta information as well. Now all the meta data is stored in the driver for each result set, so it does not depend on the MYSQL_RES structure anymore. Also add test case for invoking some meta data queries before and after fetching the result set. Change-Id: Ie8bf993926ebe89cd362ab0b311d1f3d164b84df Reviewed-on: https://gerrit.libreoffice.org/65717 Tested-by: Jenkins Reviewed-by: Tamás Bunth <btomi96@gmail.com>
Diffstat (limited to 'connectivity/qa')
-rw-r--r--connectivity/qa/connectivity/mysql/mysql.cxx42
1 files changed, 42 insertions, 0 deletions
diff --git a/connectivity/qa/connectivity/mysql/mysql.cxx b/connectivity/qa/connectivity/mysql/mysql.cxx
index f93885fb34d9..0d1d9ef85145 100644
--- a/connectivity/qa/connectivity/mysql/mysql.cxx
+++ b/connectivity/qa/connectivity/mysql/mysql.cxx
@@ -13,7 +13,10 @@
#include <com/sun/star/sdbc/XColumnLocate.hpp>
#include <com/sun/star/sdbc/XConnection.hpp>
#include <com/sun/star/sdbc/XResultSet.hpp>
+#include <com/sun/star/sdbc/XResultSetMetaData.hpp>
+#include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp>
#include <com/sun/star/sdbc/XRow.hpp>
+#include <com/sun/star/sdbc/SQLException.hpp>
#include <com/sun/star/sdbc/XParameters.hpp>
#include <com/sun/star/sdbc/XStatement.hpp>
#include <com/sun/star/sdbc/XDriver.hpp>
@@ -46,12 +49,14 @@ public:
void testIntegerInsertAndQuery();
void testDBPositionChange();
void testMultipleResultsets();
+ void testDBMetaData();
CPPUNIT_TEST_SUITE(MysqlTestDriver);
CPPUNIT_TEST(testDBConnection);
CPPUNIT_TEST(testCreateAndDropTable);
CPPUNIT_TEST(testIntegerInsertAndQuery);
CPPUNIT_TEST(testMultipleResultsets);
+ CPPUNIT_TEST(testDBMetaData);
CPPUNIT_TEST_SUITE_END();
};
@@ -289,6 +294,43 @@ void MysqlTestDriver::testMultipleResultsets()
xStatement->executeUpdate("DROP TABLE otherTable");
}
+void MysqlTestDriver::testDBMetaData()
+{
+ 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");
+
+ auto nUpdateCount = xStatement->executeUpdate(
+ "CREATE TABLE myTestTable (id INTEGER PRIMARY KEY, name VARCHAR(20))");
+ Reference<XPreparedStatement> xPrepared
+ = xConnection->prepareStatement(OUString{ "INSERT INTO myTestTable VALUES (?, ?)" });
+ Reference<XParameters> xParams(xPrepared, UNO_QUERY);
+ constexpr int ROW_COUNT = 3;
+ for (int i = 0; i < ROW_COUNT; ++i)
+ {
+ xParams->setLong(1, i);
+ xParams->setString(2, "lorem");
+ xPrepared->executeUpdate();
+ }
+
+ Reference<XResultSet> xResultSet = xStatement->executeQuery("SELECT * from myTestTable");
+ Reference<XResultSetMetaDataSupplier> xMetaDataSupplier(xResultSet, UNO_QUERY);
+ Reference<XResultSetMetaData> xMetaData = xMetaDataSupplier->getMetaData();
+ CPPUNIT_ASSERT_EQUAL(OUString{ "id" }, xMetaData->getColumnName(1));
+ CPPUNIT_ASSERT_EQUAL(OUString{ "name" }, xMetaData->getColumnName(2));
+ CPPUNIT_ASSERT(!xMetaData->isAutoIncrement(1));
+ CPPUNIT_ASSERT(!xMetaData->isCaseSensitive(2)); // default collation should be case insensitive
+ xResultSet->next(); // use it
+ // test that meta data is usable even after fetching result set
+ CPPUNIT_ASSERT_EQUAL(OUString{ "name" }, xMetaData->getColumnName(2));
+ CPPUNIT_ASSERT_THROW_MESSAGE("exception expected when indexing out of range",
+ xMetaData->getColumnName(3), sdbc::SQLException);
+ nUpdateCount = xStatement->executeUpdate("DROP TABLE myTestTable");
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(MysqlTestDriver);
CPPUNIT_PLUGIN_IMPLEMENT();