aboutsummaryrefslogtreecommitdiff
path: root/qt/mysql/date-time
diff options
context:
space:
mode:
Diffstat (limited to 'qt/mysql/date-time')
-rw-r--r--qt/mysql/date-time/driver.cxx34
-rw-r--r--qt/mysql/date-time/makefile4
-rw-r--r--qt/mysql/date-time/test.hxx17
3 files changed, 48 insertions, 7 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;
diff --git a/qt/mysql/date-time/makefile b/qt/mysql/date-time/makefile
index 039b952..ded9a6c 100644
--- a/qt/mysql/date-time/makefile
+++ b/qt/mysql/date-time/makefile
@@ -37,8 +37,8 @@ $(qt_core.l.cpp-options)
$(gen): $(odb)
$(gen): odb := $(odb)
-$(gen) $(dist): export odb_options += --database mysql --profile qt/date-time \
---generate-schema --table-prefix qt_mysql_dt_
+$(gen) $(dist): export odb_options += --database mysql --generate-schema \
+--generate-query --profile qt/date-time --table-prefix qt_mysql_dt_
$(gen): cpp_options := -I$(src_base)
$(gen): $(common.l.cpp-options) $(odb_qt.l.cpp-options) \
$(qt_core.l.cpp-options)
diff --git a/qt/mysql/date-time/test.hxx b/qt/mysql/date-time/test.hxx
index 7e58376..2570285 100644
--- a/qt/mysql/date-time/test.hxx
+++ b/qt/mysql/date-time/test.hxx
@@ -51,4 +51,21 @@ struct object
QTime time;
};
+// MySQL server version view.
+//
+#pragma db view query( \
+ "SELECT " \
+ "CAST(SUBSTRING_INDEX(@@version, '.', 1) AS UNSIGNED)," \
+ "CAST(SUBSTRING_INDEX(SUBSTRING_INDEX(@@version, '.', 2), '.', -1) AS UNSIGNED)," \
+ "CAST(SUBSTRING_INDEX(SUBSTRING_INDEX(@@version, '-', 1), '.', -1) AS UNSIGNED)," \
+ "@@protocol_version")
+struct mysql_version
+{
+ unsigned int major;
+ unsigned int minor;
+ unsigned int release;
+
+ unsigned int protocol;
+};
+
#endif // TEST_HXX