aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--oracle/types/driver.cxx7
-rw-r--r--oracle/types/test.hxx64
-rw-r--r--oracle/types/traits.hxx171
3 files changed, 217 insertions, 25 deletions
diff --git a/oracle/types/driver.cxx b/oracle/types/driver.cxx
index 2eeb2e8..371388c 100644
--- a/oracle/types/driver.cxx
+++ b/oracle/types/driver.cxx
@@ -43,7 +43,10 @@ main (int argc, char* argv[])
o.binary_float_ = 1.123F;
o.binary_double_ = 1.123;
- o.date_ = date_time (2010, 8, 29, 15, 33, 18);
+ o.date_ = date_time (2010, 8, 29, 15, 33, 18, 0);
+ o.timestamp_ = date_time (1996, 3, 9, 18, 2, 54, 123000);
+ o.interval_ds_ = time_interval (0, 0, 13, 43, 23, 19, 123000);
+ o.interval_ym_ = time_interval (12, 3, 0, 0, 0, 0, 0);
string vshort_str (8, 's');
string short_str (13, 's');
@@ -87,7 +90,7 @@ main (int argc, char* argv[])
// Testing of character set conversion to and from the client's database
// character set is disabled as the server database character set may
// not be able to represent some Unicode characters. If this were the case
- // the test outcome be a false negative.
+ // the test outcome would be a false negative.
//
// o.char_ = unicode_str;
// o.varchar2_ = unicode_str;
diff --git a/oracle/types/test.hxx b/oracle/types/test.hxx
index bfb06f9..907d310 100644
--- a/oracle/types/test.hxx
+++ b/oracle/types/test.hxx
@@ -8,6 +8,7 @@
#include <string>
#include <vector>
+#include <iostream>
#include <odb/core.hxx>
@@ -22,13 +23,15 @@ struct date_time
unsigned char d,
unsigned char h,
unsigned char min,
- unsigned char sec)
+ unsigned char sec,
+ unsigned int nsec)
: year (y),
month (m),
day (d),
hour (h),
minute (min),
- second (sec)
+ second (sec),
+ nanosecond (nsec)
{
}
@@ -41,7 +44,8 @@ struct date_time
day == y.day &&
hour == y.hour &&
minute == y.minute &&
- second == y.second;
+ second == y.second &&
+ nanosecond == y.nanosecond;
}
unsigned short year;
@@ -50,6 +54,46 @@ struct date_time
unsigned char hour;
unsigned char minute;
unsigned char second;
+ unsigned int nanosecond;
+};
+
+struct time_interval
+{
+ time_interval ()
+ {
+ }
+
+ time_interval (int y, int m, int d, int h, int min, int sec, int nsec)
+ : year (y),
+ month (m),
+ day (d),
+ hour (h),
+ minute (min),
+ second (sec),
+ nanosecond (nsec)
+ {
+ }
+
+ bool
+ operator== (const time_interval& y) const
+ {
+ return
+ year == y.year &&
+ month == y.month &&
+ day == y.day &&
+ hour == y.hour &&
+ minute == y.minute &&
+ second == y.second &&
+ nanosecond == y.nanosecond;
+ }
+
+ int year;
+ int month;
+ int day;
+ int hour;
+ int minute;
+ int second;
+ int nanosecond;
};
#pragma db object
@@ -100,9 +144,14 @@ struct object
#pragma db type ("DATE")
date_time date_;
- // @@
- // #pragma db type ("TIMESTAMP(6)")
- // date_time timestamp_;
+ #pragma db type ("TIMESTAMP(6)")
+ date_time timestamp_;
+
+ #pragma db type ("INTERVAL DAY TO SECOND")
+ time_interval interval_ds_;
+
+ #pragma db type ("INTERVAL YEAR TO MONTH")
+ time_interval interval_ym_;
// String and binary types.
//
@@ -149,6 +198,9 @@ struct object
binary_float_ == y.binary_float_ &&
binary_double_ == y.binary_double_ &&
date_ == y.date_ &&
+ timestamp_ == y.timestamp_ &&
+ interval_ds_ == y.interval_ds_ &&
+ interval_ym_ == y.interval_ym_ &&
char_ == y.char_ &&
varchar2_ == y.varchar2_ &&
nchar_ == y.nchar_ &&
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);
}
};
}