diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2012-06-27 14:55:46 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2012-06-27 14:55:46 +0200 |
commit | 0c8561962a9651ad04715d944b849410a50fa56f (patch) | |
tree | bc1afa2d167a783e32b7e80a37ed9f402780ce20 | |
parent | 81a35f69ee49de20655b677a30b872b3a9c486f6 (diff) |
Add support for mapping posix_time::ptime and QDateTime to DATE Oracle type
-rw-r--r-- | odb/qt/date-time/oracle/qdate-time-traits.hxx | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/odb/qt/date-time/oracle/qdate-time-traits.hxx b/odb/qt/date-time/oracle/qdate-time-traits.hxx index 89a1680..febfad0 100644 --- a/odb/qt/date-time/oracle/qdate-time-traits.hxx +++ b/odb/qt/date-time/oracle/qdate-time-traits.hxx @@ -10,6 +10,7 @@ #include <QtCore/QDateTime> #include <odb/oracle/traits.hxx> +#include <odb/oracle/details/date.hxx> namespace odb { @@ -70,6 +71,60 @@ namespace odb }; 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; |