From 1c9bf613aba99ca70a53b5f8f90e49225c7a56f1 Mon Sep 17 00:00:00 2001 From: Constantin Michael Date: Mon, 7 Nov 2011 15:22:44 +0200 Subject: Add tests for Oracle INTERVAL temporal types --- oracle/types/traits.hxx | 171 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 154 insertions(+), 17 deletions(-) (limited to 'oracle/types/traits.hxx') diff --git a/oracle/types/traits.hxx b/oracle/types/traits.hxx index 521bc9c..46223ea 100644 --- a/oracle/types/traits.hxx +++ b/oracle/types/traits.hxx @@ -6,9 +6,12 @@ #ifndef TRAITS_HXX #define TRAITS_HXX +#include // datetime, interval_ym, interval_ds #include -#include "test.hxx" // date_time +#include + +#include "test.hxx" // date_time, time_interval namespace odb { @@ -18,8 +21,8 @@ namespace odb class value_traits { public: - typedef long long value_type; - typedef long long query_type; + typedef date_time value_type; + typedef date_time query_type; typedef char* image_type; static void @@ -27,13 +30,21 @@ namespace odb { if (!is_null) { - v.year = (i[0] - 100) * 100; - v.year += (i[1] - 100); - v.month = i[2]; - v.day = i[3]; - v.hour = i[4] - 1; - v.minute = i[5] - 1; - v.second = i[6] - 1; + short y (0); + unsigned char m (0), d (0), h (0), min (0), s (0); + + details::get_date (i, y, m, d, h, min, s); + + v.year = y; + v.month = m; + v.day = d; + v.hour = h; + v.minute = min; + v.second = s; + + // Oracle DATE does not support fractional seconds. + // + v.nanosecond = 0; } } @@ -41,14 +52,140 @@ namespace odb set_image (char* i, bool& is_null, const date_time& v) { is_null = false; + details::set_date (i, + static_cast (v.year), + v.month, + v.day, + v.hour, + v.minute, + v.second); + } + }; + + template <> + class value_traits + { + public: + typedef date_time value_type; + typedef date_time query_type; + typedef datetime image_type; + + static void + set_value (date_time& v, const datetime& i, bool is_null) + { + if (!is_null) + { + sb2 y (0); + ub1 m (0), d (0), h (0), min (0), s (0); + ub4 ns (0); + + i.get (y, m, d, h, min, s, ns); + + v.year = y; + v.month = m; + v.day = d; + v.hour = h; + v.minute = min; + v.second = s; + v.nanosecond = ns; + } + } + + static void + set_image (datetime& i, + bool& is_null, + const date_time& v) + { + is_null = false; + + i.set (static_cast (v.year), + v.month, + v.day, + v.hour, + v.minute, + v.second, + v.nanosecond); + } + }; + + template <> + class value_traits + { + public: + typedef time_interval value_type; + typedef time_interval query_type; + typedef interval_ds image_type; + + static void + set_value (time_interval& v, + const interval_ds& i, + bool is_null) + { + if (!is_null) + { + sb4 d (0), h (0), m (0), s (0), ns (0); + i.get (d, h, m, s, ns); + + v.year = 0; + v.month = 0; + v.day = static_cast (d); + v.hour = static_cast (h); + v.minute = static_cast (m); + v.second = static_cast (s); + v.nanosecond = static_cast (ns); + } + } + + static void + set_image (interval_ds& i, + bool& is_null, + const time_interval& v) + { + is_null = false; + + i.set (v.day, + v.hour, + v.minute, + v.second, + static_cast (v.nanosecond)); + } + }; - i[0] = static_cast (v.year / 100 + 100); - i[1] = static_cast (v.year % 100 + 100); - i[2] = static_cast (v.month); - i[3] = static_cast (v.day); - i[4] = static_cast (v.hour + 1); - i[5] = static_cast (v.minute + 1); - i[6] = static_cast (v.second + 1); + template <> + class value_traits + { + public: + typedef time_interval value_type; + typedef time_interval query_type; + typedef interval_ym image_type; + + static void + set_value (time_interval& v, + const interval_ym& i, + bool is_null) + { + if (!is_null) + { + sb4 y (0), m (0); + i.get (y, m); + + v.year = static_cast (y); + v.month = static_cast (m); + v.day = 0; + v.hour = 0; + v.minute = 0; + v.second = 0; + v.nanosecond = 0; + } + } + + static void + set_image (interval_ym& i, + bool& is_null, + const time_interval& v) + { + is_null = false; + i.set (v.year, v.month); } }; } -- cgit v1.1