diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2013-07-03 11:59:08 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2013-07-03 11:59:08 +0200 |
commit | d31e96535e3f41c36646f375680d7a4efc5772b2 (patch) | |
tree | 23fc92c12ae707cd255e4d885808e824a4c25520 /qt/mysql/date-time/driver.cxx | |
parent | 6cd8b9f561b912f264ba4f723845935c40a3cb95 (diff) |
Test MySQL sub-second precision support
Diffstat (limited to 'qt/mysql/date-time/driver.cxx')
-rw-r--r-- | qt/mysql/date-time/driver.cxx | 34 |
1 files changed, 29 insertions, 5 deletions
diff --git a/qt/mysql/date-time/driver.cxx b/qt/mysql/date-time/driver.cxx index 57eab2c..f26879c 100644 --- a/qt/mysql/date-time/driver.cxx +++ b/qt/mysql/date-time/driver.cxx @@ -35,6 +35,29 @@ main (int argc, char* argv[]) { auto_ptr<database> db (create_database (argc, argv)); + mysql_version v; + { + transaction t (db->begin ()); + db->query<mysql_version> ().begin ().load (v); + t.commit (); + } + + // If we are running against MySQL 5.6.4 or later alter the tables + // to allow sub-second precision. + // + bool fs (v.major > 5 || + (v.major == 5 && (v.minor > 6 || + (v.minor == 6 && v.release >= 4)))); + if (fs) + { + transaction t (db->begin ()); + db->execute ("ALTER TABLE `qt_mysql_dt_object`" \ + " MODIFY COLUMN `date_time` DATETIME(3)," \ + " MODIFY COLUMN `timestamp` TIMESTAMP(3) NULL," \ + " MODIFY COLUMN `time` TIME(3)"); + t.commit (); + } + // // Check valid dates and times. // @@ -61,14 +84,15 @@ main (int argc, char* argv[]) // // Create a QDateTime containing the current date and time - // but with the milliseconds zeroed. MySQL does not currently - // support millisecond times. + // but with the milliseconds zeroed. MySQL prior to 5.6.4 + // does not support sub-second prevision. // QDateTime t (QDateTime::currentDateTime ()); - t.setTime (QTime (t.time ().hour (), - t.time ().minute (), - t.time ().second ())); + if (!fs) + t.setTime (QTime (t.time ().hour (), + t.time ().minute (), + t.time ().second ())); o.date = t.date (); o.date_time = t; |