aboutsummaryrefslogtreecommitdiff
path: root/odb/qt/date-time
diff options
context:
space:
mode:
authorConstantin Michael <constantin@codesynthesis.com>2011-11-11 13:43:01 +0200
committerConstantin Michael <constantin@codesynthesis.com>2011-11-11 13:43:01 +0200
commita926388f73aed90d1aa9743d32ed4c049af6bf84 (patch)
tree028846d9d85a194bd6f024f790660c566f223ea9 /odb/qt/date-time
parent2a429f33bbeffa388fd6c266e1c88a9f188256c5 (diff)
Add Oracle support for Qt profile
Diffstat (limited to 'odb/qt/date-time')
-rw-r--r--odb/qt/date-time/oracle/default-mapping.hxx29
-rw-r--r--odb/qt/date-time/oracle/qdate-time-traits.hxx81
-rw-r--r--odb/qt/date-time/oracle/qdate-traits.hxx76
-rw-r--r--odb/qt/date-time/oracle/qtime-traits.hxx66
4 files changed, 252 insertions, 0 deletions
diff --git a/odb/qt/date-time/oracle/default-mapping.hxx b/odb/qt/date-time/oracle/default-mapping.hxx
new file mode 100644
index 0000000..4411934
--- /dev/null
+++ b/odb/qt/date-time/oracle/default-mapping.hxx
@@ -0,0 +1,29 @@
+// file : odb/qt/date-time/oracle/default-mapping.hxx
+// author : Constantin Michael <constantin@codesynthesis.com>
+// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef ODB_QT_DATE_TIME_ORACLE_DEFAULT_MAPPING_HXX
+#define ODB_QT_DATE_TIME_ORACLE_DEFAULT_MAPPING_HXX
+
+#include <QtCore/QDate>
+#include <QtCore/QTime>
+#include <QtCore/QDateTime>
+
+// Map QDate to Oracle DATE by default. QDate provides a null representation
+// so allow NULL values by default.
+//
+#pragma db value(QDate) type("DATE") null
+
+// Map QTime to Oracle INTERVAL DAY(0) TO SECOND by default. QTime can only
+// represent clock times with a maximum precision of milliseconds. QTime
+// provides a null representation so allow NULL values by default.
+//
+#pragma db value(QTime) type("INTERVAL DAY(0) TO SECOND") null
+
+// Map QDateTime to ORACLE TIMESTAMP by default. QDateTime provides a null
+// representation so allow NULL values by default.
+//
+#pragma db value(QDateTime) type("TIMESTAMP(6)") null
+
+#endif // ODB_QT_DATE_TIME_ORACLE_DEFAULT_MAPPING_HXX
diff --git a/odb/qt/date-time/oracle/qdate-time-traits.hxx b/odb/qt/date-time/oracle/qdate-time-traits.hxx
new file mode 100644
index 0000000..3ecb268
--- /dev/null
+++ b/odb/qt/date-time/oracle/qdate-time-traits.hxx
@@ -0,0 +1,81 @@
+// file : odb/qt/date-time/oracle/qdate-time-traits.hxx
+// author : Constantin Michael <constantin@codesynthesis.com>
+// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef ODB_QT_DATE_TIME_ORACLE_QDATETIME_TRAITS_HXX
+#define ODB_QT_DATE_TIME_ORACLE_QDATETIME_TRAITS_HXX
+
+#include <odb/pre.hxx>
+
+#include <QtCore/QDateTime>
+
+#include <odb/oracle/traits.hxx>
+
+namespace odb
+{
+ namespace oracle
+ {
+ template <>
+ struct default_value_traits<QDateTime, id_timestamp>
+ {
+ typedef QDateTime value_type;
+ typedef QDateTime query_type;
+ typedef datetime image_type;
+
+ static void
+ set_value (QDateTime& v, const datetime& i, bool is_null)
+ {
+ if (is_null)
+ // Default constructor creates a null QDateTime.
+ //
+ v = QDateTime ();
+ else
+ {
+ 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 = QDateTime (QDate (static_cast<int> (y),
+ static_cast<int> (m),
+ static_cast<int> (d)),
+ QTime (static_cast<int> (h),
+ static_cast<int> (min),
+ static_cast<int> (s),
+ static_cast<int> (ns / 1000)));
+ }
+ }
+
+ static void
+ set_image (datetime& i, bool& is_null, const QDateTime& v)
+ {
+ if (v.isNull ())
+ is_null = true;
+ else
+ {
+ is_null = false;
+
+ const QDate& d (v.date ());
+ const QTime& t (v.time ());
+
+ i.set (static_cast<sb2> (d.year ()),
+ static_cast<ub1> (d.month ()),
+ static_cast<ub1> (d.day ()),
+ static_cast<ub1> (t.hour ()),
+ static_cast<ub1> (t.minute ()),
+ static_cast<ub1> (t.second ()),
+ static_cast<ub4> (t.msec () * 1000));
+ }
+ }
+ };
+
+ template <>
+ struct default_type_traits<QDateTime>
+ {
+ static const database_type_id db_type_od = id_timestamp;
+ };
+ }
+}
+
+#endif // ODB_QT_DATE_TIME_ORACLE_QDATETIME_TRAITS_HXX
diff --git a/odb/qt/date-time/oracle/qdate-traits.hxx b/odb/qt/date-time/oracle/qdate-traits.hxx
new file mode 100644
index 0000000..4d4f9db
--- /dev/null
+++ b/odb/qt/date-time/oracle/qdate-traits.hxx
@@ -0,0 +1,76 @@
+// file : odb/qt/date-time/oracle/qdate-traits.hxx
+// author : Constantin Michael <constantin@codesynthesis.com>
+// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef ODB_QT_DATE_TIME_ORACLE_QDATE_TRAITS_HXX
+#define ODB_QT_DATE_TIME_ORACLE_QDATE_TRAITS_HXX
+
+#include <odb/pre.hxx>
+
+#include <QtCore/QDate>
+
+#include <odb/oracle/traits.hxx>
+
+#include <odb/oracle/details/date.hxx>
+
+#include <odb/qt/date-time/exceptions.hxx>
+
+namespace odb
+{
+ namespace oracle
+ {
+ template <>
+ struct default_value_traits<QDate, id_date>
+ {
+ typedef QDate value_type;
+ typedef QDate query_type;
+ typedef char* image_type;
+
+ static void
+ set_value (QDate& v, const char* b, bool is_null)
+ {
+ if (is_null)
+ // A null QDate value is equivalent to an invalid QDate value.
+ // Set v to an invalid date to represent null.
+ //
+ v.setDate (0, 0, 0);
+ else
+ {
+ short y (0);
+ unsigned char m (0), d (0), h (0), min (0), s (0);
+ details::get_date (b, y, m, d, h, min, s);
+
+ v.setDate (y, m, d);
+ }
+ }
+
+ static void
+ set_image (char* b, bool& is_null, const QDate& v)
+ {
+ if (v.isNull ())
+ is_null = true;
+ else
+ {
+ is_null = false;
+
+ details::set_date (b,
+ static_cast<short> (v.year ()),
+ static_cast<unsigned char> (v.month ()),
+ static_cast<unsigned char> (v.day ()),
+ 0,
+ 0,
+ 0);
+ }
+ }
+ };
+
+ template <>
+ struct default_type_traits<QDate>
+ {
+ static const database_type_id db_type_id = id_date;
+ };
+ }
+}
+
+#endif // ODB_QT_DATE_TIME_ORACLE_QDATE_TRAITS_HXX
diff --git a/odb/qt/date-time/oracle/qtime-traits.hxx b/odb/qt/date-time/oracle/qtime-traits.hxx
new file mode 100644
index 0000000..b56bad5
--- /dev/null
+++ b/odb/qt/date-time/oracle/qtime-traits.hxx
@@ -0,0 +1,66 @@
+// file : odb/qt/date-time/oracle/qtime-traits.hxx
+// author : Constantin Michael <constantin@codesynthesis.com>
+// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef ODB_QT_DATE_TIME_ORACLE_QTIME_TRAITS_HXX
+#define ODB_QT_DATE_TIME_ORACLE_QTIME_TRAITS_HXX
+
+#include <odb/pre.hxx>
+
+#include <QtCore/QTime>
+
+#include <odb/oracle/traits.hxx>
+
+namespace odb
+{
+ namespace oracle
+ {
+ template <>
+ struct default_value_traits<QTime, id_interval_ds>
+ {
+ typedef QTime value_type;
+ typedef QTime query_type;
+ typedef interval_ds image_type;
+
+ static void
+ set_value (QTime& v, const interval_ds& i, bool is_null)
+ {
+ if (is_null)
+ // A null QTime value is equivalent to an invalid QTime value.
+ // Set v to an invalid time to represent null (hour value of
+ // a valid time must be in the range 0-23).
+ //
+ v.setHMS (24, 0, 0);
+ else
+ {
+ sb4 d (0), h (0), m (0), s (0), ns (0);
+ i.get (d, h, m, s, ns);
+
+ v.setHMS (h, m, s, ns / 1000);
+ }
+ }
+
+ static void
+ set_image (interval_ds& i, bool& is_null, const QTime& v)
+ {
+ if (v.isNull ())
+ is_null = true;
+ else
+ {
+ is_null = false;
+
+ i.set (0, v.hour (), v.minute (), v.second (), v.msec () * 1000);
+ }
+ }
+ };
+
+ template <>
+ struct default_type_traits<QTime>
+ {
+ static const database_type_id db_type_id = id_interval_ds;
+ };
+ }
+}
+
+#endif // ODB_QT_DATE_TIME_ORACLE_QTIME_TRAITS_HXX