summaryrefslogtreecommitdiff
path: root/libodb-qt/odb/qt/date-time
diff options
context:
space:
mode:
Diffstat (limited to 'libodb-qt/odb/qt/date-time')
-rw-r--r--libodb-qt/odb/qt/date-time/date-time-common.options4
-rw-r--r--libodb-qt/odb/qt/date-time/date-time-mssql.options13
-rw-r--r--libodb-qt/odb/qt/date-time/date-time-mysql.options13
-rw-r--r--libodb-qt/odb/qt/date-time/date-time-oracle.options13
-rw-r--r--libodb-qt/odb/qt/date-time/date-time-pgsql.options13
-rw-r--r--libodb-qt/odb/qt/date-time/date-time-sqlite.options13
-rw-r--r--libodb-qt/odb/qt/date-time/exceptions.cxx25
-rw-r--r--libodb-qt/odb/qt/date-time/exceptions.hxx34
-rw-r--r--libodb-qt/odb/qt/date-time/mssql/default-mapping.hxx31
-rw-r--r--libodb-qt/odb/qt/date-time/mssql/qdate-time-traits.hxx104
-rw-r--r--libodb-qt/odb/qt/date-time/mssql/qdate-traits.hxx63
-rw-r--r--libodb-qt/odb/qt/date-time/mssql/qtime-traits.hxx80
-rw-r--r--libodb-qt/odb/qt/date-time/mysql/default-mapping.hxx26
-rw-r--r--libodb-qt/odb/qt/date-time/mysql/qdate-time-traits.hxx135
-rw-r--r--libodb-qt/odb/qt/date-time/mysql/qdate-traits.hxx73
-rw-r--r--libodb-qt/odb/qt/date-time/mysql/qtime-traits.hxx74
-rw-r--r--libodb-qt/odb/qt/date-time/oracle/default-mapping.hxx29
-rw-r--r--libodb-qt/odb/qt/date-time/oracle/qdate-time-traits.hxx136
-rw-r--r--libodb-qt/odb/qt/date-time/oracle/qdate-traits.hxx76
-rw-r--r--libodb-qt/odb/qt/date-time/oracle/qtime-traits.hxx66
-rw-r--r--libodb-qt/odb/qt/date-time/pgsql/default-mapping.hxx26
-rw-r--r--libodb-qt/odb/qt/date-time/pgsql/qdate-time-traits.hxx70
-rw-r--r--libodb-qt/odb/qt/date-time/pgsql/qdate-traits.hxx70
-rw-r--r--libodb-qt/odb/qt/date-time/pgsql/qtime-traits.hxx73
-rw-r--r--libodb-qt/odb/qt/date-time/sqlite/default-mapping.hxx26
-rw-r--r--libodb-qt/odb/qt/date-time/sqlite/qdate-time-traits.hxx138
-rw-r--r--libodb-qt/odb/qt/date-time/sqlite/qdate-traits.hxx141
-rw-r--r--libodb-qt/odb/qt/date-time/sqlite/qtime-traits.hxx120
28 files changed, 1685 insertions, 0 deletions
diff --git a/libodb-qt/odb/qt/date-time/date-time-common.options b/libodb-qt/odb/qt/date-time/date-time-common.options
new file mode 100644
index 0000000..d813259
--- /dev/null
+++ b/libodb-qt/odb/qt/date-time/date-time-common.options
@@ -0,0 +1,4 @@
+# file : odb/qt/date-time/date-time-common.options
+# license : GNU GPL v2; see accompanying LICENSE file
+
+--profile qt/version
diff --git a/libodb-qt/odb/qt/date-time/date-time-mssql.options b/libodb-qt/odb/qt/date-time/date-time-mssql.options
new file mode 100644
index 0000000..7e35b4d
--- /dev/null
+++ b/libodb-qt/odb/qt/date-time/date-time-mssql.options
@@ -0,0 +1,13 @@
+# file : odb/qt/date-time/date-time-mssql.options
+# license : GNU GPL v2; see accompanying LICENSE file
+
+--profile qt/version
+
+# Include the default mapping in prologue instead of epilogue to
+# allow the user to override the default mapping.
+#
+--odb-prologue '#include <odb/qt/date-time/mssql/default-mapping.hxx>'
+
+--hxx-prologue '#include <odb/qt/date-time/mssql/qdate-traits.hxx>'
+--hxx-prologue '#include <odb/qt/date-time/mssql/qtime-traits.hxx>'
+--hxx-prologue '#include <odb/qt/date-time/mssql/qdate-time-traits.hxx>'
diff --git a/libodb-qt/odb/qt/date-time/date-time-mysql.options b/libodb-qt/odb/qt/date-time/date-time-mysql.options
new file mode 100644
index 0000000..fdbb364
--- /dev/null
+++ b/libodb-qt/odb/qt/date-time/date-time-mysql.options
@@ -0,0 +1,13 @@
+# file : odb/qt/date-time/date-time-mysql.options
+# license : GNU GPL v2; see accompanying LICENSE file
+
+--profile qt/version
+
+# Include the default mapping in prologue instead of epilogue to
+# allow the user to override the default mapping.
+#
+--odb-prologue '#include <odb/qt/date-time/mysql/default-mapping.hxx>'
+
+--hxx-prologue '#include <odb/qt/date-time/mysql/qdate-traits.hxx>'
+--hxx-prologue '#include <odb/qt/date-time/mysql/qtime-traits.hxx>'
+--hxx-prologue '#include <odb/qt/date-time/mysql/qdate-time-traits.hxx>'
diff --git a/libodb-qt/odb/qt/date-time/date-time-oracle.options b/libodb-qt/odb/qt/date-time/date-time-oracle.options
new file mode 100644
index 0000000..c339ce3
--- /dev/null
+++ b/libodb-qt/odb/qt/date-time/date-time-oracle.options
@@ -0,0 +1,13 @@
+# file : odb/qt/date-time/date-time-oracle.options
+# license : GNU GPL v2; see accompanying LICENSE file
+
+--profile qt/version
+
+# Include the default mapping in prologue instead of epilogue to
+# allow the user to override the default mapping.
+#
+--odb-prologue '#include <odb/qt/date-time/oracle/default-mapping.hxx>'
+
+--hxx-prologue '#include <odb/qt/date-time/oracle/qdate-traits.hxx>'
+--hxx-prologue '#include <odb/qt/date-time/oracle/qtime-traits.hxx>'
+--hxx-prologue '#include <odb/qt/date-time/oracle/qdate-time-traits.hxx>'
diff --git a/libodb-qt/odb/qt/date-time/date-time-pgsql.options b/libodb-qt/odb/qt/date-time/date-time-pgsql.options
new file mode 100644
index 0000000..9d80d48
--- /dev/null
+++ b/libodb-qt/odb/qt/date-time/date-time-pgsql.options
@@ -0,0 +1,13 @@
+# file : odb/qt/date-time/date-time-pgsql.options
+# license : GNU GPL v2; see accompanying LICENSE file
+
+--profile qt/version
+
+# Include the default mapping in prologue instead of epilogue to
+# allow the user to override the default mapping.
+#
+--odb-prologue '#include <odb/qt/date-time/pgsql/default-mapping.hxx>'
+
+--hxx-prologue '#include <odb/qt/date-time/pgsql/qdate-traits.hxx>'
+--hxx-prologue '#include <odb/qt/date-time/pgsql/qtime-traits.hxx>'
+--hxx-prologue '#include <odb/qt/date-time/pgsql/qdate-time-traits.hxx>'
diff --git a/libodb-qt/odb/qt/date-time/date-time-sqlite.options b/libodb-qt/odb/qt/date-time/date-time-sqlite.options
new file mode 100644
index 0000000..8eb1110
--- /dev/null
+++ b/libodb-qt/odb/qt/date-time/date-time-sqlite.options
@@ -0,0 +1,13 @@
+# file : odb/qt/date-time/date-time-sqlite.options
+# license : GNU GPL v2; see accompanying LICENSE file
+
+--profile qt/version
+
+# Include the default mapping in prologue instead of epilogue to
+# allow the user to override the default mapping.
+#
+--odb-prologue '#include <odb/qt/date-time/sqlite/default-mapping.hxx>'
+
+--hxx-prologue '#include <odb/qt/date-time/sqlite/qdate-traits.hxx>'
+--hxx-prologue '#include <odb/qt/date-time/sqlite/qtime-traits.hxx>'
+--hxx-prologue '#include <odb/qt/date-time/sqlite/qdate-time-traits.hxx>'
diff --git a/libodb-qt/odb/qt/date-time/exceptions.cxx b/libodb-qt/odb/qt/date-time/exceptions.cxx
new file mode 100644
index 0000000..48f0540
--- /dev/null
+++ b/libodb-qt/odb/qt/date-time/exceptions.cxx
@@ -0,0 +1,25 @@
+// file : odb/qt/date-time/exceptions.cxx
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#include <odb/qt/date-time/exceptions.hxx>
+
+namespace odb
+{
+ namespace qt
+ {
+ namespace date_time
+ {
+ const char* value_out_of_range::
+ what () const ODB_NOTHROW_NOEXCEPT
+ {
+ return "date/time value out of range";
+ }
+
+ value_out_of_range* value_out_of_range::
+ clone () const
+ {
+ return new value_out_of_range (*this);
+ }
+ }
+ }
+}
diff --git a/libodb-qt/odb/qt/date-time/exceptions.hxx b/libodb-qt/odb/qt/date-time/exceptions.hxx
new file mode 100644
index 0000000..7a73be2
--- /dev/null
+++ b/libodb-qt/odb/qt/date-time/exceptions.hxx
@@ -0,0 +1,34 @@
+// file : odb/qt/date-time/exceptions.hxx
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef ODB_QT_DATE_TIME_EXCEPTIONS_HXX
+#define ODB_QT_DATE_TIME_EXCEPTIONS_HXX
+
+#include <odb/pre.hxx>
+
+#include <odb/details/config.hxx> // ODB_NOTHROW_NOEXCEPT
+
+#include <odb/qt/exception.hxx>
+#include <odb/qt/details/export.hxx>
+
+namespace odb
+{
+ namespace qt
+ {
+ namespace date_time
+ {
+ struct LIBODB_QT_EXPORT value_out_of_range: exception
+ {
+ virtual const char*
+ what () const ODB_NOTHROW_NOEXCEPT;
+
+ virtual value_out_of_range*
+ clone () const;
+ };
+ }
+ }
+}
+
+#include <odb/post.hxx>
+
+#endif // ODB_QT_DATE_TIME_EXCEPTIONS_HXX
diff --git a/libodb-qt/odb/qt/date-time/mssql/default-mapping.hxx b/libodb-qt/odb/qt/date-time/mssql/default-mapping.hxx
new file mode 100644
index 0000000..a8acb6b
--- /dev/null
+++ b/libodb-qt/odb/qt/date-time/mssql/default-mapping.hxx
@@ -0,0 +1,31 @@
+// file : odb/qt/date-time/mssql/default-mapping.hxx
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef ODB_QT_DATE_TIME_MSSQL_DEFAULT_MAPPING_HXX
+#define ODB_QT_DATE_TIME_MSSQL_DEFAULT_MAPPING_HXX
+
+#include <QtCore/QDate>
+#include <QtCore/QTime>
+#include <QtCore/QDateTime>
+
+// By default map QDate to SQL Server DATE (available only since SQL
+// Server 2008). QDate provides a null representation so allow NULL
+// values by default.
+//
+#pragma db value(QDate) type("DATE") null
+
+// By default map QTime to SQL Server TIME(3) (available only since SQL
+// Server 2008). QTime can only represent clock times with a maximum
+// precision of milliseconds. QTime provides a null representation so
+// allow NULL values by default.
+//
+#pragma db value(QTime) type("TIME(3)") null
+
+// By default map QDateTime to SQL Server DATETIME2(3) (available only
+// since SQL Server 2008). QDateTime can only represent clock times with
+// a maximum precision of milliseconds. QDateTime provides a null
+// representation so allow NULL values by default.
+//
+#pragma db value(QDateTime) type("DATETIME2(3)") null
+
+#endif // ODB_QT_DATE_TIME_MSSQL_DEFAULT_MAPPING_HXX
diff --git a/libodb-qt/odb/qt/date-time/mssql/qdate-time-traits.hxx b/libodb-qt/odb/qt/date-time/mssql/qdate-time-traits.hxx
new file mode 100644
index 0000000..5fd8a98
--- /dev/null
+++ b/libodb-qt/odb/qt/date-time/mssql/qdate-time-traits.hxx
@@ -0,0 +1,104 @@
+// file : odb/qt/date-time/mssql/qdate-time-traits.hxx
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef ODB_QT_DATE_TIME_MSSQL_QDATETIME_TRAITS_HXX
+#define ODB_QT_DATE_TIME_MSSQL_QDATETIME_TRAITS_HXX
+
+#include <odb/pre.hxx>
+
+#include <QtCore/QDateTime>
+
+#include <odb/mssql/traits.hxx>
+
+namespace odb
+{
+ namespace mssql
+ {
+ template <>
+ struct default_value_traits<QDateTime, id_datetime>
+ {
+ typedef QDateTime value_type;
+ typedef QDateTime query_type;
+ typedef datetime image_type;
+
+ static void
+ set_value (QDateTime& v, const datetime& i, bool is_null)
+ {
+ if (is_null)
+ // Default constructor creates a null QDateTime.
+ //
+ v = QDateTime ();
+ else
+ v = QDateTime (QDate (i.year,
+ i.month,
+ i.day),
+ QTime (i.hour,
+ i.minute,
+ i.second,
+ static_cast<int> (i.fraction / 1000000)));
+ }
+
+ static void
+ set_image (datetime& i,
+ unsigned short s,
+ bool& is_null,
+ const QDateTime& v)
+ {
+ if (v.isNull ())
+ is_null = true;
+ else
+ {
+ is_null = false;
+
+ const QDate& d (v.date ());
+ const QTime& t (v.time ());
+
+ is_null = false;
+ i.year = static_cast<SQLSMALLINT> (d.year ());
+ i.month = static_cast<SQLUSMALLINT> (d.month ());
+ i.day = static_cast<SQLUSMALLINT> (d.day ());
+ i.hour = static_cast<SQLUSMALLINT> (t.hour ());
+ i.minute = static_cast<SQLUSMALLINT> (t.minute ());
+
+ // Scale value 8 indicates we are dealing with SMALLDATETIME
+ // which has the minutes precision.
+ //
+ if (s != 8)
+ {
+ i.second = static_cast<SQLUSMALLINT> (t.second ());
+
+ const unsigned int divider[8] =
+ {
+ 1000000000,
+ 100000000,
+ 10000000,
+ 1000000,
+ 100000,
+ 10000,
+ 1000,
+ 100
+ };
+
+ unsigned int ns (static_cast<unsigned int> (t.msec ()) * 1000000);
+ i.fraction = static_cast<SQLUINTEGER> (ns - ns % divider[s]);
+ }
+ else
+ {
+ i.second = 0;
+ i.fraction = 0;
+ }
+ }
+ }
+ };
+
+ template <>
+ struct default_type_traits<QDateTime>
+ {
+ static const database_type_id db_type_od = id_datetime;
+ };
+ }
+}
+
+#include <odb/post.hxx>
+
+#endif // ODB_QT_DATE_TIME_MSSQL_QDATETIME_TRAITS_HXX
diff --git a/libodb-qt/odb/qt/date-time/mssql/qdate-traits.hxx b/libodb-qt/odb/qt/date-time/mssql/qdate-traits.hxx
new file mode 100644
index 0000000..caa5d3c
--- /dev/null
+++ b/libodb-qt/odb/qt/date-time/mssql/qdate-traits.hxx
@@ -0,0 +1,63 @@
+// file : odb/qt/date-time/mssql/qdate-traits.hxx
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef ODB_QT_DATE_TIME_MSSQL_QDATE_TRAITS_HXX
+#define ODB_QT_DATE_TIME_MSSQL_QDATE_TRAITS_HXX
+
+#include <odb/pre.hxx>
+
+#include <QtCore/QDate>
+
+#include <odb/mssql/traits.hxx>
+
+#include <odb/qt/date-time/exceptions.hxx>
+
+namespace odb
+{
+ namespace mssql
+ {
+ template <>
+ struct default_value_traits<QDate, id_date>
+ {
+ typedef QDate value_type;
+ typedef QDate query_type;
+ typedef date image_type;
+
+ static void
+ set_value (QDate& v, const date& i, bool is_null)
+ {
+ if (is_null)
+ // A null QDate value is equivalent to an invalid QDate value.
+ // Set v to an invalid date to represent null.
+ //
+ v.setDate (0, 0, 0);
+ else
+ v.setDate (i.year, i.month, i.day);
+ }
+
+ static void
+ set_image (date& i, bool& is_null, const QDate& v)
+ {
+ if (v.isNull ())
+ is_null = true;
+ else
+ {
+ is_null = false;
+ i.year = static_cast<SQLSMALLINT> (v.year ());
+ i.month = static_cast<SQLUSMALLINT> (v.month ());
+ i.day = static_cast<SQLUSMALLINT> (v.day ());
+ }
+ }
+ };
+
+ template <>
+ struct default_type_traits<QDate>
+ {
+ static const database_type_id db_type_id = id_date;
+ };
+ }
+}
+
+#include <odb/post.hxx>
+
+#endif // ODB_QT_DATE_TIME_MSSQL_QDATE_TRAITS_HXX
diff --git a/libodb-qt/odb/qt/date-time/mssql/qtime-traits.hxx b/libodb-qt/odb/qt/date-time/mssql/qtime-traits.hxx
new file mode 100644
index 0000000..88fbf41
--- /dev/null
+++ b/libodb-qt/odb/qt/date-time/mssql/qtime-traits.hxx
@@ -0,0 +1,80 @@
+// file : odb/qt/date-time/mssql/qtime-traits.hxx
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef ODB_QT_DATE_TIME_MSSQL_QTIME_TRAITS_HXX
+#define ODB_QT_DATE_TIME_MSSQL_QTIME_TRAITS_HXX
+
+#include <odb/pre.hxx>
+
+#include <QtCore/QTime>
+
+#include <odb/mssql/traits.hxx>
+
+namespace odb
+{
+ namespace mssql
+ {
+ template <>
+ struct default_value_traits<QTime, id_time>
+ {
+ typedef QTime value_type;
+ typedef QTime query_type;
+ typedef time image_type;
+
+ static void
+ set_value (QTime& v, const time& i, bool is_null)
+ {
+ if (is_null)
+ // A null QTime value is equivalent to an invalid QTime value.
+ // Set v to an invalid time to represent null (hour value of
+ // a valid time must be in the range 0-23).
+ //
+ v.setHMS (24, 0, 0);
+ else
+ v.setHMS (i.hour,
+ i.minute,
+ i.second,
+ static_cast<int> (i.fraction / 1000000));
+ }
+
+ static void
+ set_image (time& i, unsigned short s, bool& is_null, const QTime& v)
+ {
+ if (v.isNull ())
+ is_null = true;
+ else
+ {
+ is_null = false;
+ i.hour = static_cast<SQLUSMALLINT> (v.hour ());
+ i.minute = static_cast<SQLUSMALLINT> (v.minute ());
+ i.second = static_cast<SQLUSMALLINT> (v.second ());
+
+ const unsigned int divider[8] =
+ {
+ 1000000000,
+ 100000000,
+ 10000000,
+ 1000000,
+ 100000,
+ 10000,
+ 1000,
+ 100
+ };
+
+ unsigned int ns (static_cast<unsigned int> (v.msec ()) * 1000000);
+ i.fraction = static_cast<SQLUINTEGER> (ns - ns % divider[s]);
+ }
+ }
+ };
+
+ template <>
+ struct default_type_traits<QTime>
+ {
+ static const database_type_id db_type_id = id_time;
+ };
+ }
+}
+
+#include <odb/post.hxx>
+
+#endif // ODB_QT_DATE_TIME_MSSQL_QTIME_TRAITS_HXX
diff --git a/libodb-qt/odb/qt/date-time/mysql/default-mapping.hxx b/libodb-qt/odb/qt/date-time/mysql/default-mapping.hxx
new file mode 100644
index 0000000..a88c507
--- /dev/null
+++ b/libodb-qt/odb/qt/date-time/mysql/default-mapping.hxx
@@ -0,0 +1,26 @@
+// file : odb/qt/date-time/mysql/default-mapping.hxx
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef ODB_QT_DATE_TIME_MYSQL_DEFAULT_MAPPING_HXX
+#define ODB_QT_DATE_TIME_MYSQL_DEFAULT_MAPPING_HXX
+
+#include <QtCore/QDate>
+#include <QtCore/QTime>
+#include <QtCore/QDateTime>
+
+// Map QDate to MySQL DATE by default. QDate provides a null
+// representation so allow NULL values by default.
+//
+#pragma db value(QDate) type("DATE") null
+
+// Map QTime to MySQL TIME by default. QTime provides a null
+// representation so allow NULL values by default.
+//
+#pragma db value(QTime) type("TIME") null
+
+// Map QDateTime to MySQL DATETIME by default. QDateTime provides a null
+// representation so allow NULL values by default.
+//
+#pragma db value(QDateTime) type("DATETIME") null
+
+#endif // ODB_QT_DATE_TIME_MYSQL_DEFAULT_MAPPING_HXX
diff --git a/libodb-qt/odb/qt/date-time/mysql/qdate-time-traits.hxx b/libodb-qt/odb/qt/date-time/mysql/qdate-time-traits.hxx
new file mode 100644
index 0000000..92279eb
--- /dev/null
+++ b/libodb-qt/odb/qt/date-time/mysql/qdate-time-traits.hxx
@@ -0,0 +1,135 @@
+// file : odb/qt/date-time/mysql/qdate-time-traits.hxx
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef ODB_QT_DATE_TIME_MYSQL_QDATETIME_TRAITS_HXX
+#define ODB_QT_DATE_TIME_MYSQL_QDATETIME_TRAITS_HXX
+
+#include <odb/pre.hxx>
+
+#include <QtCore/QDateTime>
+
+#include <odb/mysql/traits.hxx>
+
+namespace odb
+{
+ namespace mysql
+ {
+ template <>
+ struct default_value_traits<QDateTime, id_datetime>
+ {
+ typedef QDateTime value_type;
+ typedef QDateTime query_type;
+ typedef MYSQL_TIME image_type;
+
+ static void
+ set_value (QDateTime& v, const MYSQL_TIME& i, bool is_null)
+ {
+ if (is_null)
+ // Default constructor creates a null QDateTime.
+ //
+ v = QDateTime ();
+ else
+ // Since MySQL 5.6.4, the microseconds part is no longer ignored.
+ //
+ v = QDateTime (QDate (static_cast<int> (i.year),
+ static_cast<int> (i.month),
+ static_cast<int> (i.day)),
+ QTime (static_cast<int> (i.hour),
+ static_cast<int> (i.minute),
+ static_cast<int> (i.second),
+ static_cast<int> (i.second_part / 1000)));
+ }
+
+ static void
+ set_image (MYSQL_TIME& i, bool& is_null, const QDateTime& v)
+ {
+ if (v.isNull ())
+ is_null = true;
+ else
+ {
+ if ((v < QDateTime (QDate (1000, 1, 1))) ||
+ (v >= QDateTime (QDate (10000, 1, 1))))
+ throw odb::qt::date_time::value_out_of_range ();
+
+ is_null = false;
+ i.neg = false;
+
+ const QDate& d (v.date ());
+ i.year = static_cast<unsigned int> (d.year ());
+ i.month = static_cast<unsigned int> (d.month ());
+ i.day = static_cast<unsigned int> (d.day ());
+
+ const QTime& t (v.time ());
+ i.hour = static_cast<unsigned int> (t.hour ());
+ i.minute = static_cast<unsigned int> (t.minute ());
+ i.second = static_cast<unsigned int> (t.second ());
+ i.second_part = static_cast<unsigned long> (t.msec ()) * 1000;
+ }
+ }
+ };
+
+ template <>
+ struct default_value_traits<QDateTime, id_timestamp>
+ {
+ typedef QDateTime value_type;
+ typedef QDateTime query_type;
+ typedef MYSQL_TIME image_type;
+
+ static void
+ set_value (QDateTime& v, const MYSQL_TIME& i, bool is_null)
+ {
+ if (is_null)
+ // Default constructor creates a null QDateTime.
+ //
+ v = QDateTime ();
+ else
+ // Since MySQL 5.6.4, the microseconds part is no longer ignored.
+ //
+ v = QDateTime (QDate (static_cast<int> (i.year),
+ static_cast<int> (i.month),
+ static_cast<int> (i.day)),
+ QTime (static_cast<int> (i.hour),
+ static_cast<int> (i.minute),
+ static_cast<int> (i.second),
+ static_cast<int> (i.second_part / 1000)));
+ }
+
+ static void
+ set_image (MYSQL_TIME& i, bool& is_null, const QDateTime& v)
+ {
+ if (v.isNull ())
+ is_null = true;
+ else
+ {
+ if ((v <= QDateTime (QDate (1970, 1, 1))) ||
+ (v > QDateTime (QDate (2038, 1, 19), QTime (3, 14, 7))))
+ throw odb::qt::date_time::value_out_of_range ();
+
+ is_null = false;
+ i.neg = false;
+
+ const QDate& d (v.date ());
+ i.year = static_cast<unsigned int> (d.year ());
+ i.month = static_cast<unsigned int> (d.month ());
+ i.day = static_cast<unsigned int> (d.day ());
+
+ const QTime& t (v.time ());
+ i.hour = static_cast<unsigned int> (t.hour ());
+ i.minute = static_cast<unsigned int> (t.minute ());
+ i.second = static_cast<unsigned int> (t.second ());
+ i.second_part = static_cast<unsigned long> (t.msec ()) * 1000;
+ }
+ }
+ };
+
+ template <>
+ struct default_type_traits<QDateTime>
+ {
+ static const database_type_id db_type_od = id_datetime;
+ };
+ }
+}
+
+#include <odb/post.hxx>
+
+#endif // ODB_QT_DATE_TIME_MYSQL_QDATETIME_TRAITS_HXX
diff --git a/libodb-qt/odb/qt/date-time/mysql/qdate-traits.hxx b/libodb-qt/odb/qt/date-time/mysql/qdate-traits.hxx
new file mode 100644
index 0000000..12a00ec
--- /dev/null
+++ b/libodb-qt/odb/qt/date-time/mysql/qdate-traits.hxx
@@ -0,0 +1,73 @@
+// file : odb/qt/date-time/mysql/qdate-traits.hxx
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef ODB_QT_DATE_TIME_MYSQL_QDATE_TRAITS_HXX
+#define ODB_QT_DATE_TIME_MYSQL_QDATE_TRAITS_HXX
+
+#include <odb/pre.hxx>
+
+#include <QtCore/QDate>
+
+#include <odb/mysql/traits.hxx>
+#include <odb/qt/date-time/exceptions.hxx>
+
+namespace odb
+{
+ namespace mysql
+ {
+ template <>
+ struct default_value_traits<QDate, id_date>
+ {
+ typedef QDate value_type;
+ typedef QDate query_type;
+ typedef MYSQL_TIME image_type;
+
+ static void
+ set_value (QDate& v, const MYSQL_TIME& i, bool is_null)
+ {
+ if (is_null)
+ // A null QDate value is equivalent to an invalid QDate value.
+ // Set v to an invalid date to represent null.
+ //
+ v.setDate (0, 0, 0);
+ else
+ v.setDate (static_cast<int> (i.year),
+ static_cast<int> (i.month),
+ static_cast<int> (i.day));
+ }
+
+ static void
+ set_image (MYSQL_TIME& i, bool& is_null, const QDate& v)
+ {
+ if (v.isNull ())
+ is_null = true;
+ else if ((v < QDate (1000, 1, 1)) || (v > QDate (9999, 12, 31)))
+ throw odb::qt::date_time::value_out_of_range ();
+ else
+ {
+ is_null = false;
+ i.neg = false;
+
+ i.year = static_cast<unsigned int> (v.year ());
+ i.month = static_cast<unsigned int> (v.month ());
+ i.day = static_cast<unsigned int> (v.day ());
+
+ i.hour = 0;
+ i.minute = 0;
+ i.second = 0;
+ i.second_part = 0;
+ }
+ }
+ };
+
+ template <>
+ struct default_type_traits<QDate>
+ {
+ static const database_type_id db_type_id = id_date;
+ };
+ }
+}
+
+#include <odb/post.hxx>
+
+#endif // ODB_QT_DATE_TIME_MYSQL_QDATE_TRAITS_HXX
diff --git a/libodb-qt/odb/qt/date-time/mysql/qtime-traits.hxx b/libodb-qt/odb/qt/date-time/mysql/qtime-traits.hxx
new file mode 100644
index 0000000..c96e13f
--- /dev/null
+++ b/libodb-qt/odb/qt/date-time/mysql/qtime-traits.hxx
@@ -0,0 +1,74 @@
+// file : odb/qt/date-time/mysql/qtime-traits.hxx
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef ODB_QT_DATE_TIME_MYSQL_QTIME_TRAITS_HXX
+#define ODB_QT_DATE_TIME_MYSQL_QTIME_TRAITS_HXX
+
+#include <odb/pre.hxx>
+
+#include <QtCore/QTime>
+
+#include <odb/mysql/traits.hxx>
+
+namespace odb
+{
+ namespace mysql
+ {
+ template <>
+ struct default_value_traits<QTime, id_time>
+ {
+ typedef QTime value_type;
+ typedef QTime query_type;
+ typedef MYSQL_TIME image_type;
+
+ static void
+ set_value (QTime& v, const MYSQL_TIME& i, bool is_null)
+ {
+ if (is_null)
+ // A null QTime value is equivalent to an invalid QTime value.
+ // Set v to an invalid time to represent null (hour value of
+ // a valid time must be in the range 0-23).
+ //
+ v.setHMS (24, 0, 0);
+ else
+ // Since MySQL 5.6.4, the microseconds part is no longer ignored.
+ //
+ v.setHMS (static_cast<int> (i.hour),
+ static_cast<int> (i.minute),
+ static_cast<int> (i.second),
+ static_cast<int> (i.second_part / 1000));
+ }
+
+ static void
+ set_image (MYSQL_TIME& i, bool& is_null, const QTime& v)
+ {
+ if (v.isNull ())
+ is_null = true;
+ else
+ {
+ is_null = false;
+ i.neg = false;
+
+ i.year = 0;
+ i.month = 0;
+ i.day = 0;
+
+ i.hour = static_cast<unsigned int> (v.hour ());
+ i.minute = static_cast<unsigned int> (v.minute ());
+ i.second = static_cast<unsigned int> (v.second ());
+ i.second_part = static_cast<unsigned long> (v.msec ()) * 1000;
+ }
+ }
+ };
+
+ template <>
+ struct default_type_traits<QTime>
+ {
+ static const database_type_id db_type_id = id_time;
+ };
+ }
+}
+
+#include <odb/post.hxx>
+
+#endif // ODB_QT_DATE_TIME_MYSQL_QTIME_TRAITS_HXX
diff --git a/libodb-qt/odb/qt/date-time/oracle/default-mapping.hxx b/libodb-qt/odb/qt/date-time/oracle/default-mapping.hxx
new file mode 100644
index 0000000..32a733a
--- /dev/null
+++ b/libodb-qt/odb/qt/date-time/oracle/default-mapping.hxx
@@ -0,0 +1,29 @@
+// file : odb/qt/date-time/oracle/default-mapping.hxx
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef ODB_QT_DATE_TIME_ORACLE_DEFAULT_MAPPING_HXX
+#define ODB_QT_DATE_TIME_ORACLE_DEFAULT_MAPPING_HXX
+
+#include <QtCore/QDate>
+#include <QtCore/QTime>
+#include <QtCore/QDateTime>
+
+// Map QDate to Oracle DATE by default. QDate provides a null representation
+// so allow NULL values by default.
+//
+#pragma db value(QDate) type("DATE") null
+
+// Map QTime to Oracle INTERVAL DAY(0) TO SECOND(3) by default. QTime can
+// only represent clock times with a maximum precision of milliseconds.
+// QTime provides a null representation so allow NULL values by default.
+//
+#pragma db value(QTime) type("INTERVAL DAY(0) TO SECOND(3)") null
+
+// Map QDateTime to Oracle TIMESTAMP(3) by default. QDateTime can only
+// represent clock times with a maximum precision of milliseconds.
+// QDateTime provides a null representation so allow NULL values by
+// default.
+//
+#pragma db value(QDateTime) type("TIMESTAMP(3)") null
+
+#endif // ODB_QT_DATE_TIME_ORACLE_DEFAULT_MAPPING_HXX
diff --git a/libodb-qt/odb/qt/date-time/oracle/qdate-time-traits.hxx b/libodb-qt/odb/qt/date-time/oracle/qdate-time-traits.hxx
new file mode 100644
index 0000000..ba90075
--- /dev/null
+++ b/libodb-qt/odb/qt/date-time/oracle/qdate-time-traits.hxx
@@ -0,0 +1,136 @@
+// file : odb/qt/date-time/oracle/qdate-time-traits.hxx
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef ODB_QT_DATE_TIME_ORACLE_QDATETIME_TRAITS_HXX
+#define ODB_QT_DATE_TIME_ORACLE_QDATETIME_TRAITS_HXX
+
+#include <odb/pre.hxx>
+
+#include <QtCore/QDateTime>
+
+#include <odb/oracle/traits.hxx>
+#include <odb/oracle/details/date.hxx>
+
+namespace odb
+{
+ namespace oracle
+ {
+ template <>
+ struct default_value_traits<QDateTime, id_timestamp>
+ {
+ typedef QDateTime value_type;
+ typedef QDateTime query_type;
+ typedef datetime image_type;
+
+ static void
+ set_value (QDateTime& v, const datetime& i, bool is_null)
+ {
+ if (is_null)
+ // Default constructor creates a null QDateTime.
+ //
+ v = QDateTime ();
+ else
+ {
+ sb2 y (0);
+ ub1 m (0), d (0), h (0), minute (0), s (0);
+ ub4 ns (0);
+ i.get (y, m, d, h, minute, s, ns);
+
+ v = QDateTime (QDate (static_cast<int> (y),
+ static_cast<int> (m),
+ static_cast<int> (d)),
+ QTime (static_cast<int> (h),
+ static_cast<int> (minute),
+ static_cast<int> (s),
+ static_cast<int> (ns / 1000000)));
+ }
+ }
+
+ static void
+ set_image (datetime& i, bool& is_null, const QDateTime& v)
+ {
+ if (v.isNull ())
+ is_null = true;
+ else
+ {
+ is_null = false;
+
+ const QDate& d (v.date ());
+ const QTime& t (v.time ());
+
+ i.set (static_cast<sb2> (d.year ()),
+ static_cast<ub1> (d.month ()),
+ static_cast<ub1> (d.day ()),
+ static_cast<ub1> (t.hour ()),
+ static_cast<ub1> (t.minute ()),
+ static_cast<ub1> (t.second ()),
+ static_cast<ub4> (t.msec () * 1000000));
+ }
+ }
+ };
+
+ template <>
+ struct default_value_traits<QDateTime, id_date>
+ {
+ typedef QDateTime value_type;
+ typedef QDateTime query_type;
+ typedef char* image_type;
+
+ static void
+ set_value (QDateTime& v, const char* b, bool is_null)
+ {
+ if (is_null)
+ // Default constructor creates a null QDateTime.
+ //
+ v = QDateTime ();
+ else
+ {
+ short y;
+ unsigned char m, d, h, minute, s;
+
+ details::get_date (b, y, m, d, h, minute, s);
+
+ v = QDateTime (QDate (static_cast<int> (y),
+ static_cast<int> (m),
+ static_cast<int> (d)),
+ QTime (static_cast<int> (h),
+ static_cast<int> (minute),
+ static_cast<int> (s),
+ 0));
+ }
+ }
+
+ static void
+ set_image (char* b, bool& is_null, const QDateTime& v)
+ {
+ if (v.isNull ())
+ is_null = true;
+ else
+ {
+ is_null = false;
+
+ const QDate& d (v.date ());
+ const QTime& t (v.time ());
+
+ details::set_date (b,
+ static_cast<short> (d.year ()),
+ static_cast<unsigned char> (d.month ()),
+ static_cast<unsigned char> (d.day ()),
+ static_cast<unsigned char> (t.hour ()),
+ static_cast<unsigned char> (t.minute ()),
+ static_cast<unsigned char> (t.second ()));
+ }
+ }
+ };
+
+ template <>
+ struct default_type_traits<QDateTime>
+ {
+ static const database_type_id db_type_od = id_timestamp;
+ };
+ }
+}
+
+#include <odb/post.hxx>
+
+#endif // ODB_QT_DATE_TIME_ORACLE_QDATETIME_TRAITS_HXX
diff --git a/libodb-qt/odb/qt/date-time/oracle/qdate-traits.hxx b/libodb-qt/odb/qt/date-time/oracle/qdate-traits.hxx
new file mode 100644
index 0000000..f293e2d
--- /dev/null
+++ b/libodb-qt/odb/qt/date-time/oracle/qdate-traits.hxx
@@ -0,0 +1,76 @@
+// file : odb/qt/date-time/oracle/qdate-traits.hxx
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef ODB_QT_DATE_TIME_ORACLE_QDATE_TRAITS_HXX
+#define ODB_QT_DATE_TIME_ORACLE_QDATE_TRAITS_HXX
+
+#include <odb/pre.hxx>
+
+#include <QtCore/QDate>
+
+#include <odb/oracle/traits.hxx>
+
+#include <odb/oracle/details/date.hxx>
+
+#include <odb/qt/date-time/exceptions.hxx>
+
+namespace odb
+{
+ namespace oracle
+ {
+ template <>
+ struct default_value_traits<QDate, id_date>
+ {
+ typedef QDate value_type;
+ typedef QDate query_type;
+ typedef char* image_type;
+
+ static void
+ set_value (QDate& v, const char* b, bool is_null)
+ {
+ if (is_null)
+ // A null QDate value is equivalent to an invalid QDate value.
+ // Set v to an invalid date to represent null.
+ //
+ v.setDate (0, 0, 0);
+ else
+ {
+ short y (0);
+ unsigned char m (0), d (0), h (0), minute (0), s (0);
+ details::get_date (b, y, m, d, h, minute, s);
+
+ v.setDate (y, m, d);
+ }
+ }
+
+ static void
+ set_image (char* b, bool& is_null, const QDate& v)
+ {
+ if (v.isNull ())
+ is_null = true;
+ else
+ {
+ is_null = false;
+
+ details::set_date (b,
+ static_cast<short> (v.year ()),
+ static_cast<unsigned char> (v.month ()),
+ static_cast<unsigned char> (v.day ()),
+ 0,
+ 0,
+ 0);
+ }
+ }
+ };
+
+ template <>
+ struct default_type_traits<QDate>
+ {
+ static const database_type_id db_type_id = id_date;
+ };
+ }
+}
+
+#include <odb/post.hxx>
+
+#endif // ODB_QT_DATE_TIME_ORACLE_QDATE_TRAITS_HXX
diff --git a/libodb-qt/odb/qt/date-time/oracle/qtime-traits.hxx b/libodb-qt/odb/qt/date-time/oracle/qtime-traits.hxx
new file mode 100644
index 0000000..0d9aff4
--- /dev/null
+++ b/libodb-qt/odb/qt/date-time/oracle/qtime-traits.hxx
@@ -0,0 +1,66 @@
+// file : odb/qt/date-time/oracle/qtime-traits.hxx
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef ODB_QT_DATE_TIME_ORACLE_QTIME_TRAITS_HXX
+#define ODB_QT_DATE_TIME_ORACLE_QTIME_TRAITS_HXX
+
+#include <odb/pre.hxx>
+
+#include <QtCore/QTime>
+
+#include <odb/oracle/traits.hxx>
+
+namespace odb
+{
+ namespace oracle
+ {
+ template <>
+ struct default_value_traits<QTime, id_interval_ds>
+ {
+ typedef QTime value_type;
+ typedef QTime query_type;
+ typedef interval_ds image_type;
+
+ static void
+ set_value (QTime& v, const interval_ds& i, bool is_null)
+ {
+ if (is_null)
+ // A null QTime value is equivalent to an invalid QTime value.
+ // Set v to an invalid time to represent null (hour value of
+ // a valid time must be in the range 0-23).
+ //
+ v.setHMS (24, 0, 0);
+ else
+ {
+ sb4 d (0), h (0), m (0), s (0), ns (0);
+ i.get (d, h, m, s, ns);
+
+ v.setHMS (h, m, s, ns / 1000000);
+ }
+ }
+
+ static void
+ set_image (interval_ds& i, bool& is_null, const QTime& v)
+ {
+ if (v.isNull ())
+ is_null = true;
+ else
+ {
+ is_null = false;
+
+ i.set (0, v.hour (), v.minute (), v.second (), v.msec () * 1000000);
+ }
+ }
+ };
+
+ template <>
+ struct default_type_traits<QTime>
+ {
+ static const database_type_id db_type_id = id_interval_ds;
+ };
+ }
+}
+
+#include <odb/post.hxx>
+
+#endif // ODB_QT_DATE_TIME_ORACLE_QTIME_TRAITS_HXX
diff --git a/libodb-qt/odb/qt/date-time/pgsql/default-mapping.hxx b/libodb-qt/odb/qt/date-time/pgsql/default-mapping.hxx
new file mode 100644
index 0000000..cd3b1b5
--- /dev/null
+++ b/libodb-qt/odb/qt/date-time/pgsql/default-mapping.hxx
@@ -0,0 +1,26 @@
+// file : odb/qt/date-time/pgsql/default-mapping.hxx
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef ODB_QT_DATE_TIME_PGSQL_DEFAULT_MAPPING_HXX
+#define ODB_QT_DATE_TIME_PGSQL_DEFAULT_MAPPING_HXX
+
+#include <QtCore/QDate>
+#include <QtCore/QTime>
+#include <QtCore/QDateTime>
+
+// Map QDate to PostgreSQL DATE by default. QDate provides a null
+// representation so allow NULL values by default.
+//
+#pragma db value(QDate) type("DATE") null
+
+// Map QTime to PostgreSQL TIME by default. QTime provides a null
+// representation so allow NULL values by default.
+//
+#pragma db value(QTime) type("TIME") null
+
+// Map QDateTime to PostgreSQL TIMESTAMP by default. QDateTime provides a null
+// representation so allow NULL values by default.
+//
+#pragma db value(QDateTime) type("TIMESTAMP") null
+
+#endif // ODB_QT_DATE_TIME_PGSQL_DEFAULT_MAPPING_HXX
diff --git a/libodb-qt/odb/qt/date-time/pgsql/qdate-time-traits.hxx b/libodb-qt/odb/qt/date-time/pgsql/qdate-time-traits.hxx
new file mode 100644
index 0000000..a9fe757
--- /dev/null
+++ b/libodb-qt/odb/qt/date-time/pgsql/qdate-time-traits.hxx
@@ -0,0 +1,70 @@
+// file : odb/qt/date-time/pgsql/qdatetime-traits.hxx
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef ODB_QT_DATE_TIME_PGSQL_QDATETIME_TRAITS_HXX
+#define ODB_QT_DATE_TIME_PGSQL_QDATETIME_TRAITS_HXX
+
+#include <odb/pre.hxx>
+
+#include <QtCore/QDateTime>
+
+#include <odb/pgsql/traits.hxx>
+
+namespace odb
+{
+ namespace pgsql
+ {
+ // Implementation of mapping between QDateTime and PostgreSQL TIMESTAMP.
+ // TIMESTAMP values are stored as micro-seconds since the PostgreSQL
+ // epoch 2000-01-01.
+ //
+ template <>
+ struct default_value_traits<QDateTime, id_timestamp>
+ {
+ typedef details::endian_traits endian_traits;
+
+ typedef QDateTime value_type;
+ typedef QDateTime query_type;
+ typedef long long image_type;
+
+ static void
+ set_value (QDateTime& v, long long i, bool is_null)
+ {
+ if (is_null)
+ // Default constructor creates a null QDateTime.
+ //
+ v = QDateTime ();
+ else
+ {
+ const QDateTime pg_epoch (QDate (2000, 1, 1), QTime (0, 0, 0));
+ v = pg_epoch.addMSecs (
+ static_cast <qint64> (endian_traits::ntoh (i) / 1000LL));
+ }
+ }
+
+ static void
+ set_image (long long& i, bool& is_null, const QDateTime& v)
+ {
+ if (v.isNull ())
+ is_null = true;
+ else
+ {
+ is_null = false;
+ const QDateTime pg_epoch (QDate (2000, 1, 1), QTime (0, 0, 0));
+ i = endian_traits::hton (
+ static_cast<long long> (pg_epoch.msecsTo (v)) * 1000LL);
+ }
+ }
+ };
+
+ template <>
+ struct default_type_traits<QDateTime>
+ {
+ static const database_type_id db_type_id = id_timestamp;
+ };
+ }
+}
+
+#include <odb/post.hxx>
+
+#endif // ODB_QT_DATE_TIME_PGSQL_QDATETIME_TRAITS_HXX
diff --git a/libodb-qt/odb/qt/date-time/pgsql/qdate-traits.hxx b/libodb-qt/odb/qt/date-time/pgsql/qdate-traits.hxx
new file mode 100644
index 0000000..b7cc7d4
--- /dev/null
+++ b/libodb-qt/odb/qt/date-time/pgsql/qdate-traits.hxx
@@ -0,0 +1,70 @@
+// file : odb/qt/date-time/pgsql/qdate-traits.hxx
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef ODB_QT_DATE_TIME_PGSQL_QDATE_TRAITS_HXX
+#define ODB_QT_DATE_TIME_PGSQL_QDATE_TRAITS_HXX
+
+#include <odb/pre.hxx>
+
+#include <QtCore/QDate>
+
+#include <odb/pgsql/traits.hxx>
+
+namespace odb
+{
+ namespace pgsql
+ {
+ // Implementation of the mapping between QDate and PostgreSQL DATE. The
+ // DATE values are stored as days since the PostgreSQL epoch 2000-01-01.
+ //
+ template <>
+ struct default_value_traits<QDate, id_date>
+ {
+ typedef details::endian_traits endian_traits;
+
+ typedef QDate value_type;
+ typedef QDate query_type;
+ typedef int image_type;
+
+ static void
+ set_value (QDate& v, int i, bool is_null)
+ {
+ if (is_null)
+ // A null QDate value is equivalent to an invalid QDate value.
+ // Set v to an invalid date to represent null.
+ //
+ v.setDate (0, 0, 0);
+ else
+ {
+ const QDate pg_epoch (2000, 1, 1);
+ v = pg_epoch.addDays (endian_traits::ntoh (i));
+ }
+ }
+
+ static void
+ set_image (int& i, bool& is_null, const QDate& v)
+ {
+ if (v.isNull ())
+ is_null = true;
+ else
+ {
+ is_null = false;
+ const QDate pg_epoch (2000, 1, 1);
+ // In Qt5 daysTo() returns qint64.
+ //
+ i = endian_traits::hton (static_cast<int> (pg_epoch.daysTo (v)));
+ }
+ }
+ };
+
+ template <>
+ struct default_type_traits<QDate>
+ {
+ static const database_type_id db_type_id = id_date;
+ };
+ }
+}
+
+#include <odb/post.hxx>
+
+#endif // ODB_QT_DATE_TIME_PGSQL_QDATE_TRAITS_HXX
diff --git a/libodb-qt/odb/qt/date-time/pgsql/qtime-traits.hxx b/libodb-qt/odb/qt/date-time/pgsql/qtime-traits.hxx
new file mode 100644
index 0000000..86a594b
--- /dev/null
+++ b/libodb-qt/odb/qt/date-time/pgsql/qtime-traits.hxx
@@ -0,0 +1,73 @@
+// file : odb/qt/date-time/pgsql/qtime-traits.hxx
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef ODB_QT_DATE_TIME_PGSQL_QTIME_TRAITS_HXX
+#define ODB_QT_DATE_TIME_PGSQL_QTIME_TRAITS_HXX
+
+#include <odb/pre.hxx>
+
+#include <QtCore/QTime>
+
+#include <odb/pgsql/traits.hxx>
+
+namespace odb
+{
+ namespace pgsql
+ {
+ // Implementation of the mapping between QTime and PostgreSQL TIME. The
+ // TIME values are stored as micro-seconds since 00:00:00.
+ //
+ template <>
+ struct default_value_traits<QTime, id_time>
+ {
+ typedef details::endian_traits endian_traits;
+
+ typedef QTime value_type;
+ typedef QTime query_type;
+ typedef long long image_type;
+
+ static void
+ set_value (QTime& v, long long i, bool is_null)
+ {
+ if (is_null)
+ // A null QTime value is equivalent to an invalid QTime value.
+ // Set v to an invalid time to represent null (hour value of
+ // a valid time must be in the range 0-23).
+ //
+ v.setHMS (24, 0, 0);
+ else
+ {
+ const QTime base (0, 0, 0);
+
+ v = base.addMSecs (
+ static_cast<int> (endian_traits::ntoh (i) / 1000));
+ }
+ }
+
+ static void
+ set_image (long long& i, bool& is_null, const QTime& v)
+ {
+ if (v.isNull ())
+ is_null = true;
+ else
+ {
+ is_null = false;
+ const QTime base (0, 0, 0);
+
+ i = endian_traits::hton (
+ static_cast<long long> (base.msecsTo (v)) * 1000);
+ }
+ }
+ };
+
+ template <>
+ struct default_type_traits<QTime>
+ {
+ static const database_type_id db_type_id = id_time;
+ };
+ }
+}
+
+#include <odb/post.hxx>
+
+#endif // ODB_QT_DATE_TIME_PGSQL_QTIME_TRAITS_HXX
diff --git a/libodb-qt/odb/qt/date-time/sqlite/default-mapping.hxx b/libodb-qt/odb/qt/date-time/sqlite/default-mapping.hxx
new file mode 100644
index 0000000..a150ca9
--- /dev/null
+++ b/libodb-qt/odb/qt/date-time/sqlite/default-mapping.hxx
@@ -0,0 +1,26 @@
+// file : odb/qt/date-time/sqlite/default-mapping.hxx
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef ODB_QT_DATE_TIME_SQLITE_DEFAULT_MAPPING_HXX
+#define ODB_QT_DATE_TIME_SQLITE_DEFAULT_MAPPING_HXX
+
+#include <QtCore/QDate>
+#include <QtCore/QTime>
+#include <QtCore/QDateTime>
+
+// Map QDate to SQLite TEXT by default. QDate provides a null representation
+// so allow NULL values by default.
+//
+#pragma db value(QDate) type("TEXT") null
+
+// Map QTime to SQLite TEXT by default. QTime provides a null representation
+// so allow NULL values by default.
+//
+#pragma db value(QTime) type("TEXT") null
+
+// Map QDateTime to SQLite TEXT by default. QDateTime provides a null
+// representation so allow NULL values by default.
+//
+#pragma db value(QDateTime) type("TEXT") null
+
+#endif // ODB_QT_DATE_TIME_SQLITE_DEFAULT_MAPPING_HXX
diff --git a/libodb-qt/odb/qt/date-time/sqlite/qdate-time-traits.hxx b/libodb-qt/odb/qt/date-time/sqlite/qdate-time-traits.hxx
new file mode 100644
index 0000000..db561fc
--- /dev/null
+++ b/libodb-qt/odb/qt/date-time/sqlite/qdate-time-traits.hxx
@@ -0,0 +1,138 @@
+// file : odb/qt/date-time/sqlite/qdatetime-traits.hxx
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef ODB_QT_DATE_TIME_SQLITE_QDATETIME_TRAITS_HXX
+#define ODB_QT_DATE_TIME_SQLITE_QDATETIME_TRAITS_HXX
+
+#include <odb/pre.hxx>
+
+#include <string>
+#include <cstddef> // std::size_t
+#include <cstring> // std::memcpy
+
+#include <QtCore/QtGlobal> // QT_VERSION
+
+#include <QtCore/QDateTime>
+
+#include <odb/details/buffer.hxx>
+#include <odb/sqlite/traits.hxx>
+#include <odb/qt/date-time/exceptions.hxx>
+
+namespace odb
+{
+ namespace sqlite
+ {
+ template <>
+ struct default_value_traits<QDateTime, id_text>
+ {
+ typedef QDateTime value_type;
+ typedef QDateTime query_type;
+ typedef details::buffer image_type;
+
+ static void
+ set_value (QDateTime& v,
+ const details::buffer& i,
+ std::size_t n,
+ bool is_null)
+ {
+ if (is_null)
+ // Default constructor creates a null QDateTime.
+ //
+ v = QDateTime ();
+ else
+ v = QDateTime::fromString (
+ QString::fromLatin1 (i.data (), static_cast<int> (n)),
+ "yyyy-MM-ddTHH:mm:ss.zzz");
+ }
+
+ static void
+ set_image (details::buffer& i,
+ std::size_t& n,
+ bool& is_null,
+ const QDateTime& v)
+ {
+ if (v.isNull ())
+ is_null = true;
+ else
+ {
+ is_null = false;
+
+ // Cannot use toStdString() here since Qt could have been
+ // configured without the STL compatibility support.
+ //
+ std::string s (
+ v.toString ("yyyy-MM-ddTHH:mm:ss.zzz").toLatin1 ().constData ());
+
+ n = s.size ();
+ if (n > i.capacity ())
+ i.capacity (n);
+
+ std::memcpy (i.data (), s.data (), n);
+ }
+ }
+ };
+
+ // Implementation of mapping between QDateTime and SQLite INTEGER.
+ // The integer value represents UNIX time.
+ //
+ template <>
+ struct default_value_traits<QDateTime, id_integer>
+ {
+ typedef QDateTime value_type;
+ typedef QDateTime query_type;
+ typedef long long image_type;
+
+ static void
+ set_value (QDateTime& v, long long i, bool is_null)
+ {
+ if (is_null)
+ // Default constructor creates a null QDateTime.
+ //
+ v = QDateTime ();
+ else
+ {
+ v.setTimeSpec (Qt::UTC);
+
+ // *Time_t() functions are deprecated in favor of *SecsSinceEpoch().
+ //
+#if QT_VERSION < 0x060000
+ v.setTime_t (static_cast<uint> (i));
+#else
+ v.setSecsSinceEpoch (static_cast<qint64> (i));
+#endif
+ }
+ }
+
+ static void
+ set_image (long long& i, bool& is_null, const QDateTime& v)
+ {
+ if (v.isNull ())
+ is_null = true;
+ else if (v < QDateTime (QDate (1970, 1, 1),
+ QTime (0, 0, 0),
+ Qt::UTC))
+ throw odb::qt::date_time::value_out_of_range ();
+ else
+ {
+ is_null = false;
+
+#if QT_VERSION < 0x060000
+ i = static_cast<long long> (v.toTime_t ());
+#else
+ i = static_cast<long long> (v.toSecsSinceEpoch ());
+#endif
+ }
+ }
+ };
+
+ template <>
+ struct default_type_traits<QDateTime>
+ {
+ static const database_type_id db_type_id = id_text;
+ };
+ }
+}
+
+#include <odb/post.hxx>
+
+#endif // ODB_QT_DATE_TIME_SQLITE_QDATETIME_TRAITS_HXX
diff --git a/libodb-qt/odb/qt/date-time/sqlite/qdate-traits.hxx b/libodb-qt/odb/qt/date-time/sqlite/qdate-traits.hxx
new file mode 100644
index 0000000..52721b7
--- /dev/null
+++ b/libodb-qt/odb/qt/date-time/sqlite/qdate-traits.hxx
@@ -0,0 +1,141 @@
+// file : odb/qt/date-time/sqlite/qdate-traits.hxx
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef ODB_QT_DATE_TIME_SQLITE_QDATE_TRAITS_HXX
+#define ODB_QT_DATE_TIME_SQLITE_QDATE_TRAITS_HXX
+
+#include <odb/pre.hxx>
+
+#include <string>
+#include <cstddef> // std::size_t
+#include <cstring> // std::memcpy
+
+#include <QtCore/QtGlobal> // QT_VERSION
+
+#include <QtCore/QDate>
+#include <QtCore/QDateTime>
+
+#include <odb/details/buffer.hxx>
+#include <odb/sqlite/traits.hxx>
+#include <odb/qt/date-time/exceptions.hxx>
+
+namespace odb
+{
+ namespace sqlite
+ {
+ template <>
+ struct default_value_traits<QDate, id_text>
+ {
+ typedef QDate value_type;
+ typedef QDate query_type;
+ typedef details::buffer image_type;
+
+ static void
+ set_value (QDate& v,
+ const details::buffer& i,
+ std::size_t n,
+ bool is_null)
+ {
+ if (is_null)
+ // A null QDate value is equivalent to an invalid QDate value.
+ // Set v to an invalid date to represent null.
+ //
+ v.setDate (0, 0, 0);
+ else
+ v = QDate::fromString (
+ QString::fromLatin1 (i.data (), static_cast<int> (n)),
+ "yyyy-MM-dd");
+ }
+
+ static void
+ set_image (details::buffer& i,
+ std::size_t& n,
+ bool& is_null,
+ const QDate& v)
+ {
+ if (v.isNull ())
+ is_null = true;
+ else
+ {
+ is_null = false;
+
+ // Cannot use toStdString() here since Qt could have been
+ // configured without the STL compatibility support.
+ //
+ std::string s (v.toString ("yyyy-MM-dd").toLatin1 ().constData ());
+
+ n = s.size ();
+ if (n > i.capacity ())
+ i.capacity (n);
+
+ std::memcpy (i.data (), s.data (), n);
+ }
+ }
+ };
+
+ // Implementation of the mapping between QDate and SQLite INTEGER. The
+ // integer value represents UNIX time.
+ //
+ template <>
+ struct default_value_traits<QDate, id_integer>
+ {
+ typedef QDate value_type;
+ typedef QDate query_type;
+ typedef long long image_type;
+
+ static void
+ set_value (QDate& v, long long i, bool is_null)
+ {
+ if (is_null)
+ // A null QDate value is equivalent to an invalid QDate value.
+ // Set v to an invalid date to represent null.
+ //
+ v.setDate (0, 0, 0);
+ else
+ {
+ QDateTime dt;
+ dt.setTimeSpec (Qt::UTC);
+
+ // *Time_t() functions are deprecated in favor of *SecsSinceEpoch().
+ //
+#if QT_VERSION < 0x060000
+ dt.setTime_t (static_cast<uint> (i));
+#else
+ dt.setSecsSinceEpoch (static_cast<qint64> (i));
+#endif
+ v = dt.date ();
+ }
+ }
+
+ static void
+ set_image (long long& i, bool& is_null, const QDate& v)
+ {
+ if (v.isNull ())
+ is_null = true;
+ else if (v < QDate (1970, 1, 1))
+ throw odb::qt::date_time::value_out_of_range ();
+ else
+ {
+ is_null = false;
+ const QDateTime dt (v, QTime (0, 0, 0), Qt::UTC);
+
+#if QT_VERSION < 0x060000
+ i = static_cast<long long> (dt.toTime_t ());
+#else
+ i = static_cast<long long> (dt.toSecsSinceEpoch ());
+#endif
+ }
+ }
+ };
+
+ template <>
+ struct default_type_traits<QDate>
+ {
+ static const database_type_id db_type_id = id_text;
+ };
+ }
+}
+
+#include <odb/post.hxx>
+
+#endif // ODB_QT_DATE_TIME_SQLITE_QDATE_TRAITS_HXX
diff --git a/libodb-qt/odb/qt/date-time/sqlite/qtime-traits.hxx b/libodb-qt/odb/qt/date-time/sqlite/qtime-traits.hxx
new file mode 100644
index 0000000..dd86399
--- /dev/null
+++ b/libodb-qt/odb/qt/date-time/sqlite/qtime-traits.hxx
@@ -0,0 +1,120 @@
+// file : odb/qt/date-time/sqlite/qtime-traits.hxx
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef ODB_QT_DATE_TIME_SQLITE_QTIME_TRAITS_HXX
+#define ODB_QT_DATE_TIME_SQLITE_QTIME_TRAITS_HXX
+
+#include <odb/pre.hxx>
+
+#include <string>
+#include <cstddef> // std::size_t
+#include <cstring> // std::memcpy
+
+#include <QtCore/QTime>
+
+#include <odb/details/buffer.hxx>
+#include <odb/sqlite/traits.hxx>
+
+namespace odb
+{
+ namespace sqlite
+ {
+ template <>
+ struct default_value_traits<QTime, id_text>
+ {
+ typedef QTime value_type;
+ typedef QTime query_type;
+ typedef details::buffer image_type;
+
+ static void
+ set_value (QTime& v,
+ const details::buffer& i,
+ std::size_t n,
+ bool is_null)
+ {
+ if (is_null)
+ // A null QTime value is equivalent to an invalid QTime value.
+ // Set v to an invalid time to represent null (hour value of
+ // a valid time must be in the range 0-23).
+ //
+ v.setHMS (24, 0, 0);
+ else
+ v = QTime::fromString (
+ QString::fromLatin1 (i.data (), static_cast<int> (n)),
+ "HH:mm:ss.zzz");
+ }
+
+ static void
+ set_image (details::buffer& i,
+ std::size_t& n,
+ bool& is_null,
+ const QTime& v)
+ {
+ if (v.isNull ())
+ is_null = true;
+ else
+ {
+ is_null = false;
+
+ // Cannot use toStdString() here since Qt could have been
+ // configured without the STL compatibility support.
+ //
+ std::string s (
+ v.toString ("HH:mm:ss.zzz").toLatin1 ().constData ());
+
+ n = s.size ();
+ if (n > i.capacity ())
+ i.capacity (n);
+
+ std::memcpy (i.data (), s.data (), n);
+ }
+ }
+ };
+
+ // Implementation of mapping between QTime and SQLite INTEGER. The
+ // integer value represents seconds since midnight.
+ //
+ template <>
+ struct default_value_traits<QTime, id_integer>
+ {
+ typedef QTime value_type;
+ typedef QTime query_type;
+ typedef long long image_type;
+
+ static void
+ set_value (QTime& v, long long i, bool is_null)
+ {
+ if (is_null)
+ // A null QTime value is equivalent to an invalid QTime value.
+ // Set v to an invalid time to represent null (hour value of
+ // a valid time must be in the range 0-23).
+ //
+ v.setHMS (24, 0, 0);
+ else
+ v = QTime (0, 0, 0).addSecs (static_cast<int> (i));
+ }
+
+ static void
+ set_image (long long& i, bool& is_null, const QTime& v)
+ {
+ if (v.isNull ())
+ is_null = true;
+ else
+ {
+ is_null = false;
+ i = static_cast<long long> (QTime (0, 0, 0).secsTo (v));
+ }
+ }
+ };
+
+ template <>
+ struct default_type_traits<QTime>
+ {
+ static const database_type_id db_type_id = id_text;
+ };
+ }
+}
+
+#include <odb/post.hxx>
+
+#endif // ODB_QT_DATE_TIME_SQLITE_QTIME_TRAITS_HXX