aboutsummaryrefslogtreecommitdiff
path: root/boost/mysql/date-time
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2013-07-03 11:59:08 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2013-07-03 11:59:08 +0200
commitd31e96535e3f41c36646f375680d7a4efc5772b2 (patch)
tree23fc92c12ae707cd255e4d885808e824a4c25520 /boost/mysql/date-time
parent6cd8b9f561b912f264ba4f723845935c40a3cb95 (diff)
Test MySQL sub-second precision support
Diffstat (limited to 'boost/mysql/date-time')
-rw-r--r--boost/mysql/date-time/driver.cxx47
-rw-r--r--boost/mysql/date-time/makefile4
-rw-r--r--boost/mysql/date-time/test.hxx17
3 files changed, 61 insertions, 7 deletions
diff --git a/boost/mysql/date-time/driver.cxx b/boost/mysql/date-time/driver.cxx
index 49d94b7..6ffe051 100644
--- a/boost/mysql/date-time/driver.cxx
+++ b/boost/mysql/date-time/driver.cxx
@@ -37,6 +37,35 @@ 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 `boost_mysql_dt_object_durations`" \
+ " MODIFY COLUMN `value` TIME(6)");
+
+ db->execute ("ALTER TABLE `boost_mysql_dt_object_times`" \
+ " MODIFY COLUMN `value` DATETIME(6)");
+
+ db->execute ("ALTER TABLE `boost_mysql_dt_object_timestamps`" \
+ " MODIFY COLUMN `value` TIMESTAMP(6) NULL");
+
+ t.commit ();
+ }
+
object o;
// Test all valid date-time mappings.
@@ -46,13 +75,16 @@ main (int argc, char* argv[])
o.dates.push_back (date (max_date_time));
o.dates.push_back (date (min_date_time));
- o.times.push_back (second_clock::local_time ());
+ if (fs)
+ o.times.push_back (microsec_clock::local_time ());
+ else
+ o.times.push_back (second_clock::local_time ());
o.times.push_back (not_a_date_time);
o.times.push_back (min_date_time);
- // MySQL time interface does not support fraction seconds. Construct
- // with zero fractional seconds so that comparison test does not
- // fail for invalid reasons.
+ // MySQL prior to 5.6.4 does not support fraction seconds. Construct
+ // with zero fractional seconds so that comparison test does not fail
+ // for invalid reasons.
//
o.times.push_back (
ptime (
@@ -62,10 +94,15 @@ main (int argc, char* argv[])
ptime (max_date_time).time_of_day ().minutes (),
ptime (max_date_time).time_of_day ().seconds ())));
- o.timestamps.push_back (second_clock::local_time ());
+ if (fs)
+ o.timestamps.push_back (microsec_clock::local_time ());
+ else
+ o.timestamps.push_back (second_clock::local_time ());
o.timestamps.push_back (not_a_date_time);
o.durations.push_back (time_duration (1, 2, 3));
+ if (fs)
+ o.durations.back () += time_duration (microseconds (123456));
o.durations.push_back (time_duration (-1, 2, 3));
o.durations.push_back (not_a_date_time);
diff --git a/boost/mysql/date-time/makefile b/boost/mysql/date-time/makefile
index aaff422..c6c60fd 100644
--- a/boost/mysql/date-time/makefile
+++ b/boost/mysql/date-time/makefile
@@ -41,8 +41,8 @@ $(boost.l.cpp-options)
$(gen): $(odb)
$(gen): odb := $(odb)
-$(gen) $(dist): export odb_options += --database mysql --profile boost/date-time \
---generate-schema --table-prefix boost_mysql_dt_
+$(gen) $(dist): export odb_options += --database mysql --generate-schema \
+--generate-query --profile boost/date-time --table-prefix boost_mysql_dt_
$(gen): cpp_options := -I$(src_base)
$(gen): $(common.l.cpp-options) $(odb_boost.l.cpp-options) \
$(boost.l.cpp-options)
diff --git a/boost/mysql/date-time/test.hxx b/boost/mysql/date-time/test.hxx
index 6244177..253ebb1 100644
--- a/boost/mysql/date-time/test.hxx
+++ b/boost/mysql/date-time/test.hxx
@@ -46,4 +46,21 @@ struct object
std::vector<boost::posix_time::time_duration> durations;
};
+// 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