aboutsummaryrefslogtreecommitdiff
path: root/odb/boost/date-time
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2012-06-27 14:55:45 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2012-06-27 14:55:45 +0200
commitf7c7f67c92dc33586c64eb2bc02fe4649c0eebfb (patch)
tree6e159c4ae4647970070da0241984359f0473300d /odb/boost/date-time
parent98eae2e174b98b8f84dc562d3236d1f274af9085 (diff)
Add support for mapping posix_time::ptime and QDateTime to DATE Oracle type
Diffstat (limited to 'odb/boost/date-time')
-rw-r--r--odb/boost/date-time/oracle/posix-time-traits.hxx67
1 files 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 <odb/oracle/traits.hxx>
#include <odb/oracle/oracle-fwd.hxx> // ub1, sb2, ub4
-#include <odb/oracle/oracle-types.hxx> // odb::oracle::datetime,
- // odb::oracle::interval_ds
+#include <odb/oracle/oracle-types.hxx> // odb::oracle::{datetime interval_ds}
+#include <odb/oracle/details/date.hxx>
#include <odb/boost/date-time/exceptions.hxx>
@@ -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<date::year_type> (y),
+ static_cast<date::month_type> (m),
+ static_cast<date::day_type> (d)),
+ time_duration (
+ static_cast<time_duration::hour_type> (h),
+ static_cast<time_duration::min_type> (minute),
+ static_cast<time_duration::sec_type> (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<short> (d.year ()),
+ static_cast<unsigned char> (d.month ()),
+ static_cast<unsigned char> (d.day ()),
+ static_cast<unsigned char> (t.hours ()),
+ static_cast<unsigned char> (t.minutes ()),
+ static_cast<unsigned char> (t.seconds ()));
+ }
+ }
+ };
+
+ template <>
struct default_value_traits< ::boost::posix_time::time_duration,
id_interval_ds>
{