diff options
author | Tamas Bunth <tamas.bunth@collabora.co.uk> | 2019-04-22 19:09:24 +0200 |
---|---|---|
committer | Andras Timar <andras.timar@collabora.com> | 2019-04-25 15:47:38 +0200 |
commit | 406aef41d1368a46d36757072592e93efd9ae08e (patch) | |
tree | 8678ca1aedae07fcaf02fba6b5fef9c0a7012074 /connectivity/qa | |
parent | 7ec3baef938d62d16558b7ee7fd84eb02b206551 (diff) |
mysqlc: Allow conversions between different types
Change-Id: I54c1f438a755267db0896637c79f915de9113f83
Reviewed-on: https://gerrit.libreoffice.org/71074
Tested-by: Jenkins
Reviewed-by: Andras Timar <andras.timar@collabora.com>
Diffstat (limited to 'connectivity/qa')
-rw-r--r-- | connectivity/qa/connectivity/mysql/mysql.cxx | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/connectivity/qa/connectivity/mysql/mysql.cxx b/connectivity/qa/connectivity/mysql/mysql.cxx index 1cbe34790421..00ff9423aa4a 100644 --- a/connectivity/qa/connectivity/mysql/mysql.cxx +++ b/connectivity/qa/connectivity/mysql/mysql.cxx @@ -53,6 +53,7 @@ public: void testMultipleResultsets(); void testDBMetaData(); void testTimestampField(); + void testNumericConversionPrepared(); CPPUNIT_TEST_SUITE(MysqlTestDriver); CPPUNIT_TEST(testDBConnection); @@ -61,6 +62,7 @@ public: CPPUNIT_TEST(testMultipleResultsets); CPPUNIT_TEST(testDBMetaData); CPPUNIT_TEST(testTimestampField); + CPPUNIT_TEST(testNumericConversionPrepared); CPPUNIT_TEST_SUITE_END(); }; @@ -373,6 +375,36 @@ void MysqlTestDriver::testTimestampField() xStatement->executeUpdate("DROP TABLE myTestTable"); } +/** + * Test getting value from a decimal type column from a result set of a + * prepared statement, getting as a tinyint, string, short, int, long. + */ +void MysqlTestDriver::testNumericConversionPrepared() +{ + 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"); + + xStatement->executeUpdate("CREATE TABLE myTestTable (myDecimal DECIMAL(4,2))"); + xStatement->executeUpdate("INSERT INTO myTestTable VALUES (11.22)"); + Reference<XPreparedStatement> xPrepared + = xConnection->prepareStatement("SELECT * from myTestTable"); + Reference<XResultSet> xResultSet = xPrepared->executeQuery(); + xResultSet->next(); // use it + Reference<XRow> xRow(xResultSet, UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("11.22"), xRow->getString(1)); + // converting to integer types results in rounding down the number + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int8>(11), xRow->getByte(1)); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int16>(11), xRow->getShort(1)); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(11), xRow->getInt(1)); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int64>(11), xRow->getLong(1)); + + xStatement->executeUpdate("DROP TABLE myTestTable"); +} + CPPUNIT_TEST_SUITE_REGISTRATION(MysqlTestDriver); CPPUNIT_PLUGIN_IMPLEMENT(); |