summaryrefslogtreecommitdiffstats
path: root/connectivity/qa
diff options
context:
space:
mode:
authorTamas Bunth <tamas.bunth@collabora.co.uk>2019-01-29 13:00:21 +0100
committerTamás Bunth <btomi96@gmail.com>2019-01-29 18:07:08 +0100
commit76491860113d60965cd234770afcef747fe4bd65 (patch)
tree3c374ff615384741ee918a38cfb62e2083d3ba21 /connectivity/qa
parentgive better warning explanation (diff)
downloadcore-76491860113d60965cd234770afcef747fe4bd65.tar.gz
core-76491860113d60965cd234770afcef747fe4bd65.zip
mysqlc: fix timestamp query of result set
Also add test for inserting and reading timestamp values. Change-Id: I2ba997c438f4e33965b0fe0602e58eddeff38b01 Reviewed-on: https://gerrit.libreoffice.org/67066 Tested-by: Jenkins Reviewed-by: Tamás Bunth <btomi96@gmail.com>
Diffstat (limited to 'connectivity/qa')
-rw-r--r--connectivity/qa/connectivity/mysql/mysql.cxx36
1 files changed, 36 insertions, 0 deletions
diff --git a/connectivity/qa/connectivity/mysql/mysql.cxx b/connectivity/qa/connectivity/mysql/mysql.cxx
index bfefeec132c1..1cbe34790421 100644
--- a/connectivity/qa/connectivity/mysql/mysql.cxx
+++ b/connectivity/qa/connectivity/mysql/mysql.cxx
@@ -20,6 +20,8 @@
#include <com/sun/star/sdbc/XParameters.hpp>
#include <com/sun/star/sdbc/XStatement.hpp>
#include <com/sun/star/sdbc/XDriver.hpp>
+
+#include <com/sun/star/util/DateTime.hpp>
#include <svtools/miscopt.hxx>
#include <osl/process.h>
@@ -50,6 +52,7 @@ public:
void testDBPositionChange();
void testMultipleResultsets();
void testDBMetaData();
+ void testTimestampField();
CPPUNIT_TEST_SUITE(MysqlTestDriver);
CPPUNIT_TEST(testDBConnection);
@@ -57,6 +60,7 @@ public:
CPPUNIT_TEST(testIntegerInsertAndQuery);
CPPUNIT_TEST(testMultipleResultsets);
CPPUNIT_TEST(testDBMetaData);
+ CPPUNIT_TEST(testTimestampField);
CPPUNIT_TEST_SUITE_END();
};
@@ -337,6 +341,38 @@ void MysqlTestDriver::testDBMetaData()
nUpdateCount = xStatement->executeUpdate("DROP TABLE myTestTable");
}
+void MysqlTestDriver::testTimestampField()
+{
+ 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 (id INTEGER PRIMARY KEY, mytimestamp timestamp)");
+ xStatement->executeUpdate("INSERT INTO myTestTable VALUES (1, '2008-02-16 20:15:03')");
+
+ // now let's query
+ Reference<XResultSet> xResultSet
+ = xStatement->executeQuery("SELECT mytimestamp from myTestTable");
+
+ xResultSet->next(); // use it
+ Reference<XRow> xRow(xResultSet, UNO_QUERY);
+ CPPUNIT_ASSERT_MESSAGE("cannot extract row from result set!", xRow.is());
+ util::DateTime dt = xRow->getTimestamp(1);
+ CPPUNIT_ASSERT_EQUAL(static_cast<short>(2008), dt.Year);
+ CPPUNIT_ASSERT_EQUAL(static_cast<unsigned short>(2), dt.Month);
+ CPPUNIT_ASSERT_EQUAL(static_cast<unsigned short>(16), dt.Day);
+
+ CPPUNIT_ASSERT_EQUAL(static_cast<unsigned short>(20), dt.Hours);
+ CPPUNIT_ASSERT_EQUAL(static_cast<unsigned short>(15), dt.Minutes);
+ CPPUNIT_ASSERT_EQUAL(static_cast<unsigned short>(3), dt.Seconds);
+
+ xStatement->executeUpdate("DROP TABLE myTestTable");
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(MysqlTestDriver);
CPPUNIT_PLUGIN_IMPLEMENT();