From f7c7f67c92dc33586c64eb2bc02fe4649c0eebfb Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 27 Jun 2012 14:55:45 +0200 Subject: Add support for mapping posix_time::ptime and QDateTime to DATE Oracle type --- odb/boost/date-time/oracle/posix-time-traits.hxx | 67 +++++++++++++++++++++++- 1 file changed, 65 insertions(+), 2 deletions(-) diff --git a/odb/boost/date-time/oracle/posix-time-traits.hxx b/odb/boost/date-time/oracle/posix-time-traits.hxx index 3c1ea39..0ac1411 100644 --- a/odb/boost/date-time/oracle/posix-time-traits.hxx +++ b/odb/boost/date-time/oracle/posix-time-traits.hxx @@ -13,8 +13,8 @@ #include #include // ub1, sb2, ub4 -#include // odb::oracle::datetime, - // odb::oracle::interval_ds +#include // odb::oracle::{datetime interval_ds} +#include #include @@ -94,6 +94,69 @@ namespace odb }; template <> + struct default_value_traits< ::boost::posix_time::ptime, id_date> + { + typedef ::boost::posix_time::ptime ptime; + typedef ::boost::posix_time::time_duration time_duration; + typedef ::boost::gregorian::date date; + + typedef ptime value_type; + typedef ptime query_type; + typedef char* image_type; + + static void + set_value (ptime& v, const char* b, bool is_null) + { + if (is_null) + v = ptime (::boost::date_time::not_a_date_time); + else + { + short y; + unsigned char m, d, h, minute, s; + + details::get_date (b, y, m, d, h, minute, s); + + v = ptime ( + date (static_cast (y), + static_cast (m), + static_cast (d)), + time_duration ( + static_cast (h), + static_cast (minute), + static_cast (s), + 0)); + } + } + + static void + set_image (char* b, bool& is_null, const ptime& v) + { + if (v.is_special ()) + { + if (v.is_not_a_date_time ()) + is_null = true; + else + throw odb::boost::date_time::special_value (); + } + else + { + is_null = false; + + const date& d (v.date ()); + const time_duration& t (v.time_of_day ()); + + details::set_date (b, + static_cast (d.year ()), + static_cast (d.month ()), + static_cast (d.day ()), + static_cast (t.hours ()), + static_cast (t.minutes ()), + static_cast (t.seconds ())); + } + } + }; + + template <> struct default_value_traits< ::boost::posix_time::time_duration, id_interval_ds> { -- cgit v1.1