aboutsummaryrefslogtreecommitdiff
path: root/odb/boost/date-time
diff options
context:
space:
mode:
authorConstantin Michael <constantin@codesynthesis.com>2011-07-21 23:58:04 +0200
committerConstantin Michael <constantin@codesynthesis.com>2011-07-22 09:59:37 +0200
commit90fe9df73ca0804b21d1036c6f7e3c4464838a13 (patch)
tree1022f8bb3f4cad4fd7838c900755843423637590 /odb/boost/date-time
parente0cfcb1f9e9ab1b468189a5ee45c46f7f22bd174 (diff)
Add PostgreSQL support to Boost profile
Diffstat (limited to 'odb/boost/date-time')
-rw-r--r--odb/boost/date-time/gregorian-pgsql.options9
-rw-r--r--odb/boost/date-time/pgsql/gregorian-mapping.hxx16
-rw-r--r--odb/boost/date-time/pgsql/gregorian-traits.hxx71
-rw-r--r--odb/boost/date-time/pgsql/posix-time-mapping.hxx21
-rw-r--r--odb/boost/date-time/pgsql/posix-time-traits.hxx159
-rw-r--r--odb/boost/date-time/posix-time-pgsql.options9
6 files changed, 285 insertions, 0 deletions
diff --git a/odb/boost/date-time/gregorian-pgsql.options b/odb/boost/date-time/gregorian-pgsql.options
new file mode 100644
index 0000000..368fed9
--- /dev/null
+++ b/odb/boost/date-time/gregorian-pgsql.options
@@ -0,0 +1,9 @@
+# file : odb/boost/date-time/gregorian-pgsql.options
+# author : Constantin Michael <constantin@codesynthesis.com>
+# copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC
+# license : GNU GPL v2; see accompanying LICENSE file
+
+--profile boost/version
+
+--odb-epilogue '#include <odb/boost/date-time/pgsql/gregorian-mapping.hxx>'
+--hxx-prologue '#include <odb/boost/date-time/pgsql/gregorian-traits.hxx>'
diff --git a/odb/boost/date-time/pgsql/gregorian-mapping.hxx b/odb/boost/date-time/pgsql/gregorian-mapping.hxx
new file mode 100644
index 0000000..073e46d
--- /dev/null
+++ b/odb/boost/date-time/pgsql/gregorian-mapping.hxx
@@ -0,0 +1,16 @@
+// file : odb/boost/date-time/pgsql/gregorian-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_BOOST_DATE_TIME_PGSQL_GREGORIAN_MAPPING_HXX
+#define ODB_BOOST_DATE_TIME_PGSQL_GREGORIAN_MAPPING_HXX
+
+#include <boost/date_time/gregorian/gregorian_types.hpp>
+
+// By default map boost::gregorian::date to PostgreSQL DATE. We use the
+// NULL value to represent not_a_date_time.
+//
+#pragma db value(boost::gregorian::date) type("DATE") null
+
+#endif // ODB_BOOST_DATE_TIME_PGSQL_GREGORIAN_MAPPING_HXX
diff --git a/odb/boost/date-time/pgsql/gregorian-traits.hxx b/odb/boost/date-time/pgsql/gregorian-traits.hxx
new file mode 100644
index 0000000..0bb3590
--- /dev/null
+++ b/odb/boost/date-time/pgsql/gregorian-traits.hxx
@@ -0,0 +1,71 @@
+// file : odb/boost/date-time/pgsql/gregorian-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_BOOST_DATE_TIME_PGSQL_GREGORIAN_TRAITS_HXX
+#define ODB_BOOST_DATE_TIME_PGSQL_GREGORIAN_TRAITS_HXX
+
+#include <odb/pre.hxx>
+
+#include <boost/date_time/gregorian/gregorian_types.hpp>
+
+#include <odb/core.hxx>
+#include <odb/pgsql/traits.hxx>
+#include <odb/boost/date-time/exceptions.hxx>
+
+namespace odb
+{
+ namespace pgsql
+ {
+ template <>
+ struct default_value_traits< ::boost::gregorian::date, id_date>
+ {
+ typedef ::boost::gregorian::date date;
+
+ typedef details::endian_traits endian_traits;
+
+ typedef date value_type;
+ typedef date query_type;
+ typedef int image_type;
+
+ static void
+ set_value (date& v, int i, bool is_null)
+ {
+ if (is_null)
+ v = date (::boost::date_time::not_a_date_time);
+ else
+ v = date (2000, 1, 1) + ::boost::gregorian::date_duration (
+ endian_traits::ntoh (i));
+ }
+
+ static void
+ set_image (int& i, bool& is_null, const date& v)
+ {
+ if (v.is_special ())
+ {
+ if (v.is_not_a_date ())
+ is_null = true;
+ else
+ throw odb::boost::date_time::special_value ();
+ }
+ else
+ {
+ is_null = false;
+ i = endian_traits::hton (
+ static_cast<int> ((v - date (2000, 1, 1)).days ()));
+ }
+ }
+ };
+
+ template <>
+ struct default_type_traits< ::boost::gregorian::date>
+ {
+ static const database_type_id db_type_id = id_date;
+ };
+ }
+}
+
+#include <odb/post.hxx>
+
+#endif // ODB_BOOST_DATE_TIME_PGSQL_GREGORIAN_TRAITS_HXX
diff --git a/odb/boost/date-time/pgsql/posix-time-mapping.hxx b/odb/boost/date-time/pgsql/posix-time-mapping.hxx
new file mode 100644
index 0000000..68bd30c
--- /dev/null
+++ b/odb/boost/date-time/pgsql/posix-time-mapping.hxx
@@ -0,0 +1,21 @@
+// file : odb/boost/date-time/pgsql/posix-time-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_BOOST_DATE_TIME_PGSQL_POSIX_TIME_MAPPING_HXX
+#define ODB_BOOST_DATE_TIME_PGSQL_POSIX_TIME_MAPPING_HXX
+
+#include <boost/date_time/posix_time/posix_time_types.hpp>
+
+// By default map boost::posix_time::ptime to PostgreSQL TIMESTAMP. We use
+// the NULL value to represent not_a_date_time.
+//
+#pragma db value(boost::posix_time::ptime) type("TIMESTAMP") null
+
+// By default map boost::posix_time::time_duration to PostgreSQL TIME. We
+// use the NULL value to represent not_a_date_time.
+//
+#pragma db value(boost::posix_time::time_duration) type("TIME") null
+
+#endif // ODB_BOOST_DATE_TIME_PGSQL_POSIX_TIME_MAPPING_HXX
diff --git a/odb/boost/date-time/pgsql/posix-time-traits.hxx b/odb/boost/date-time/pgsql/posix-time-traits.hxx
new file mode 100644
index 0000000..375a5e4
--- /dev/null
+++ b/odb/boost/date-time/pgsql/posix-time-traits.hxx
@@ -0,0 +1,159 @@
+// file : odb/boost/date-time/pgsql/posix-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_BOOST_DATE_TIME_PGSQL_POSIX_TIME_TRAITS_HXX
+#define ODB_BOOST_DATE_TIME_PGSQL_POSIX_TIME_TRAITS_HXX
+
+#include <odb/pre.hxx>
+
+#include <ctime>
+
+#include <boost/date_time/posix_time/posix_time_types.hpp>
+#include <boost/date_time/posix_time/conversion.hpp> // from_time_t
+
+#include <odb/core.hxx>
+#include <odb/pgsql/traits.hxx>
+#include <odb/boost/date-time/exceptions.hxx>
+
+namespace odb
+{
+ namespace pgsql
+ {
+ // Implementation of the mapping between boost::posix_time::ptime and
+ // PostgreSQL TIMESTAMP. TIMESTAMP values are stored as micro-seconds
+ // since the PostgreSQL epoch 2000-01-01.
+ //
+ template <>
+ struct default_value_traits< ::boost::posix_time::ptime, id_timestamp>
+ {
+ typedef ::boost::gregorian::date date;
+ typedef ::boost::posix_time::ptime ptime;
+ typedef ::boost::posix_time::time_duration time_duration;
+
+ typedef details::endian_traits endian_traits;
+
+ typedef ptime value_type;
+ typedef ptime query_type;
+ typedef long long image_type;
+
+ // The difference between the Unix epoch and the PostgreSQL epoch
+ // in seconds.
+ //
+ static const long long epoch_diff = 946684800LL;
+
+ static const long long neg_inf = -0x7fffffffffffffffLL - 1;
+ static const long long pos_inf = 0x7fffffffffffffffLL;
+
+ static void
+ set_value (ptime& v, long long i, bool is_null)
+ {
+ if (is_null)
+ v = ptime (::boost::date_time::not_a_date_time);
+ else
+ {
+ i = endian_traits::ntoh (i);
+
+ if (i == neg_inf)
+ v = ptime (::boost::date_time::neg_infin);
+ else if (i == pos_inf)
+ v = ptime (::boost::date_time::pos_infin);
+ else
+ v = ::boost::posix_time::from_time_t (
+ static_cast<std::time_t> (i / 1000000 + epoch_diff));
+ }
+ }
+
+ static void
+ set_image (long long& i, bool& is_null, const ptime& v)
+ {
+ is_null = false;
+
+ if (v.is_special ())
+ {
+ if (v.is_not_a_date_time ())
+ is_null = true;
+ else if (v.is_neg_infinity ())
+ i = endian_traits::hton (neg_inf);
+ else if (v.is_pos_infinity ())
+ i = endian_traits::hton (pos_inf);
+ else
+ throw odb::boost::date_time::special_value ();
+ }
+ else
+ {
+ const ptime unix_epoch (date (1970, 1, 1), time_duration (0, 0, 0));
+
+ long long pg_seconds (
+ static_cast<long long> (
+ (v - unix_epoch).ticks () / time_duration::ticks_per_second ()) -
+ epoch_diff);
+
+ i = endian_traits::hton (pg_seconds * 1000000);
+ }
+ }
+ };
+
+ // Implementation of the mapping between boost::posix_time::time_duration
+ // and PostgreSQL TIME. The TIME values are stores as micro-seconds since
+ // 00:00:00.
+ //
+ template <>
+ struct default_value_traits< ::boost::posix_time::time_duration, id_time>
+ {
+ typedef ::boost::posix_time::time_duration time_duration;
+
+ typedef details::endian_traits endian_traits;
+
+ typedef time_duration value_type;
+ typedef time_duration query_type;
+ typedef long long image_type;
+
+ static void
+ set_value (time_duration& v, long long i, bool is_null)
+ {
+ if (is_null)
+ v = time_duration (::boost::date_time::not_a_date_time);
+ else
+ v = time_duration (0, 0,
+ static_cast<long> (
+ endian_traits::ntoh (i) / 1000000));
+ }
+
+ static void
+ set_image (long long& i, bool& is_null, const time_duration& v)
+ {
+ if (v.is_special ())
+ {
+ if (v.is_not_a_date_time ())
+ is_null = true;
+ else
+ throw odb::boost::date_time::special_value ();
+ }
+ else if (v.hours () < 0 || v.hours () > 24)
+ throw odb::boost::date_time::value_out_of_range ();
+ else
+ {
+ is_null = false;
+ i = endian_traits::hton (
+ static_cast<long long> (v.total_seconds ()) * 1000000);
+ }
+ }
+ };
+
+ template <>
+ struct default_type_traits< ::boost::posix_time::ptime>
+ {
+ static const database_type_id db_type_id = id_timestamp;
+ };
+
+ template <>
+ struct default_type_traits< ::boost::posix_time::time_duration>
+ {
+ static const database_type_id db_type_id = id_time;
+ };
+ }
+}
+
+#endif // ODB_BOOST_DATE_TIME_PGSQL_POSIX_TIME_TRAITS_HXX
diff --git a/odb/boost/date-time/posix-time-pgsql.options b/odb/boost/date-time/posix-time-pgsql.options
new file mode 100644
index 0000000..e0abc81
--- /dev/null
+++ b/odb/boost/date-time/posix-time-pgsql.options
@@ -0,0 +1,9 @@
+# file : odb/boost/date-time/posix-time-pgsql.options
+# author : Constantin Michael <constantin@codesynthesis.com>
+# copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC
+# license : GNU GPL v2; see accompanying LICENSE file
+
+--profile boost/version
+
+--odb-epilogue '#include <odb/boost/date-time/pgsql/posix-time-mapping.hxx>'
+--hxx-prologue '#include <odb/boost/date-time/pgsql/posix-time-traits.hxx>'