aboutsummaryrefslogtreecommitdiff
path: root/oracle/types/traits.hxx
diff options
context:
space:
mode:
Diffstat (limited to 'oracle/types/traits.hxx')
-rw-r--r--oracle/types/traits.hxx171
1 files changed, 154 insertions, 17 deletions
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 <odb/oracle/oracle-types.hxx> // datetime, interval_ym, interval_ds
#include <odb/oracle/traits.hxx>
-#include "test.hxx" // date_time
+#include <odb/oracle/details/date.hxx>
+
+#include "test.hxx" // date_time, time_interval
namespace odb
{
@@ -18,8 +21,8 @@ namespace odb
class value_traits<date_time, id_date>
{
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<unsigned short> (v.year),
+ v.month,
+ v.day,
+ v.hour,
+ v.minute,
+ v.second);
+ }
+ };
+
+ template <>
+ class value_traits<date_time, id_timestamp>
+ {
+ 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<sb2> (v.year),
+ v.month,
+ v.day,
+ v.hour,
+ v.minute,
+ v.second,
+ v.nanosecond);
+ }
+ };
+
+ template <>
+ class value_traits<time_interval, id_interval_ds>
+ {
+ 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<unsigned char> (d);
+ v.hour = static_cast<unsigned char> (h);
+ v.minute = static_cast<unsigned char> (m);
+ v.second = static_cast<unsigned char> (s);
+ v.nanosecond = static_cast<unsigned int> (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<sb4> (v.nanosecond));
+ }
+ };
- i[0] = static_cast<char> (v.year / 100 + 100);
- i[1] = static_cast<char> (v.year % 100 + 100);
- i[2] = static_cast<char> (v.month);
- i[3] = static_cast<char> (v.day);
- i[4] = static_cast<char> (v.hour + 1);
- i[5] = static_cast<char> (v.minute + 1);
- i[6] = static_cast<char> (v.second + 1);
+ template <>
+ class value_traits<time_interval, id_interval_ym>
+ {
+ 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<unsigned short> (y);
+ v.month = static_cast<unsigned char> (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);
}
};
}