aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--odb/pgsql/pgsql-types.hxx3
-rw-r--r--odb/pgsql/query.hxx186
-rw-r--r--odb/pgsql/statement.cxx35
-rw-r--r--odb/pgsql/traits.hxx22
4 files changed, 145 insertions, 101 deletions
diff --git a/odb/pgsql/pgsql-types.hxx b/odb/pgsql/pgsql-types.hxx
index 3abd4fc..1d83b9f 100644
--- a/odb/pgsql/pgsql-types.hxx
+++ b/odb/pgsql/pgsql-types.hxx
@@ -30,6 +30,9 @@ namespace odb
real, // Buffer is float; size, capacity, truncated are unused.
double_, // Buffer is double; size, capacity, truncated are unused.
numeric, // Buffer is a char array.
+ date, // Buffer is int; size, capacity, truncated are unused.
+ time, // Buffer is long long; size, capacity, truncated are unused.
+ timestamp,// Buffer is long long; size, capacity, truncated are unused.
text, // Buffer is a char array.
bytea, // Buffer is a char array.
bit, // Buffer is a char array.
diff --git a/odb/pgsql/query.hxx b/odb/pgsql/query.hxx
index 933ecd9..879517c 100644
--- a/odb/pgsql/query.hxx
+++ b/odb/pgsql/query.hxx
@@ -1306,107 +1306,125 @@ namespace odb
// unsigned long size_;
// };
- // @@ DATE
+ // DATE
//
- // template <typename T>
- // struct query_param_impl<T, id_date>: query_param
- // {
- // query_param_impl (ref_bind<T> r) : query_param (&r.ref) {}
- // query_param_impl (val_bind<T> v) : query_param (0) {init (v.val);}
+ template <typename T>
+ struct query_param_impl<T, id_date>: query_param
+ {
+ query_param_impl (ref_bind<T> r) : query_param (&r.ref) {}
+ query_param_impl (val_bind<T> v) : query_param (0) {init (v.val);}
- // virtual bool
- // init ()
- // {
- // init (*static_cast<const T*> (value_));
- // return false;
- // }
+ virtual bool
+ init ()
+ {
+ init (*static_cast<const T*> (value_));
+ return false;
+ }
- // virtual void
- // bind (MYSQL_BIND* b)
- // {
- // b->buffer_type = MYSQL_TYPE_DATE;
- // b->buffer = &image_;
- // }
+ virtual void
+ bind (pgsql::bind* b)
+ {
+ b->type = bind::date;
+ b->buffer = &image_;
+ }
- // private:
- // void
- // init (const T& v)
- // {
- // bool dummy;
- // value_traits<T, id_date>::set_image (image_, dummy, v);
- // }
+ virtual unsigned int
+ oid () const
+ {
+ return date_oid;
+ }
- // private:
- // MYSQL_TIME image_;
- // };
+ private:
+ void
+ init (const T& v)
+ {
+ bool dummy;
+ value_traits<T, id_date>::set_image (image_, dummy, v);
+ }
+
+ private:
+ int image_;
+ };
- // @@ TIME
+ // TIME
//
- // template <typename T>
- // struct query_param_impl<T, id_time>: query_param
- // {
- // query_param_impl (ref_bind<T> r) : query_param (&r.ref) {}
- // query_param_impl (val_bind<T> v) : query_param (0) {init (v.val);}
+ template <typename T>
+ struct query_param_impl<T, id_time>: query_param
+ {
+ query_param_impl (ref_bind<T> r) : query_param (&r.ref) {}
+ query_param_impl (val_bind<T> v) : query_param (0) {init (v.val);}
- // virtual bool
- // init ()
- // {
- // init (*static_cast<const T*> (value_));
- // return false;
- // }
+ virtual bool
+ init ()
+ {
+ init (*static_cast<const T*> (value_));
+ return false;
+ }
- // virtual void
- // bind (MYSQL_BIND* b)
- // {
- // b->buffer_type = MYSQL_TYPE_TIME;
- // b->buffer = &image_;
- // }
+ virtual void
+ bind (pgsql::bind* b)
+ {
+ b->type = bind::time;
+ b->buffer = &image_;
+ }
- // private:
- // void
- // init (const T& v)
- // {
- // bool dummy;
- // value_traits<T, id_time>::set_image (image_, dummy, v);
- // }
+ virtual unsigned int
+ oid () const
+ {
+ return time_oid;
+ }
- // private:
- // MYSQL_TIME image_;
- // };
+ private:
+ void
+ init (const T& v)
+ {
+ bool dummy;
+ value_traits<T, id_time>::set_image (image_, dummy, v);
+ }
+
+ private:
+ long long image_;
+ };
- // @@ TIMESTAMP
+ // TIMESTAMP
//
- // template <typename T>
- // struct query_param_impl<T, id_timestamp>: query_param
- // {
- // query_param_impl (ref_bind<T> r) : query_param (&r.ref) {}
- // query_param_impl (val_bind<T> v) : query_param (0) {init (v.val);}
+ template <typename T>
+ struct query_param_impl<T, id_timestamp>: query_param
+ {
+ query_param_impl (ref_bind<T> r) : query_param (&r.ref) {}
+ query_param_impl (val_bind<T> v) : query_param (0) {init (v.val);}
- // virtual bool
- // init ()
- // {
- // init (*static_cast<const T*> (value_));
- // return false;
- // }
+ virtual bool
+ init ()
+ {
+ init (*static_cast<const T*> (value_));
+ return false;
+ }
- // virtual void
- // bind (MYSQL_BIND* b)
- // {
- // b->buffer_type = MYSQL_TYPE_TIMESTAMP;
- // b->buffer = &image_;
- // }
+ virtual void
+ bind (pgsql::bind* b)
+ {
+ b->type = bind::timestamp;
+ b->buffer = &image_;
+ }
- // private:
- // void
- // init (const T& v)
- // {
- // bool dummy;
- // value_traits<T, id_timestamp>::set_image (image_, dummy, v);
- // }
+ virtual unsigned int
+ oid () const
+ {
+ return timestamp_oid;
+ }
- // private:
- // MYSQL_TIME image_;
- // };
+ private:
+ void
+ init (const T& v)
+ {
+ bool dummy;
+ value_traits<T, id_timestamp>::set_image (image_, dummy, v);
+ }
+
+ private:
+ long long image_;
+ };
// STRING
//
diff --git a/odb/pgsql/statement.cxx b/odb/pgsql/statement.cxx
index e9497df..cb49332 100644
--- a/odb/pgsql/statement.cxx
+++ b/odb/pgsql/statement.cxx
@@ -89,7 +89,7 @@ namespace odb
n.values[i] = reinterpret_cast<char*> (current_bind.buffer);
- // Use text format for numeric/decimal types and binary format
+ // Use text format for numeric types and binary format
// for all others.
//
if (current_bind.type == bind::numeric)
@@ -132,6 +132,17 @@ namespace odb
l = sizeof (double);
break;
}
+ case bind::date:
+ {
+ l = sizeof (int);
+ break;
+ }
+ case bind::time:
+ case bind::timestamp:
+ {
+ l = sizeof (long long);
+ break;
+ }
case bind::uuid:
{
// UUID is a 16-byte sequence.
@@ -195,7 +206,9 @@ namespace odb
case bind::boolean:
{
*static_cast<bool*> (b.buffer) =
- reinterpret_cast<const bool*> (v);
+ *reinterpret_cast<const bool*> (v);
+
+ break;
}
case bind::smallint:
{
@@ -206,8 +219,7 @@ namespace odb
}
case bind::integer:
{
- *static_cast<int*> (b.buffer) =
- *reinterpret_cast<const int*> (v);
+ *static_cast<int*> (b.buffer) = *reinterpret_cast<const int*> (v);
break;
}
@@ -232,6 +244,20 @@ namespace odb
break;
}
+ case bind::date:
+ {
+ *static_cast<int*> (b.buffer) = *reinterpret_cast<const int*> (v);
+
+ break;
+ }
+ case bind::time:
+ case bind::timestamp:
+ {
+ *static_cast<long long*> (b.buffer) =
+ *reinterpret_cast<const long long*> (v);
+
+ break;
+ }
case bind::numeric:
case bind::text:
case bind::bytea:
@@ -256,6 +282,7 @@ namespace odb
case bind::uuid:
{
memcpy (b.buffer, v, 16);
+
break;
}
}
diff --git a/odb/pgsql/traits.hxx b/odb/pgsql/traits.hxx
index 1fbcc26..8308688 100644
--- a/odb/pgsql/traits.hxx
+++ b/odb/pgsql/traits.hxx
@@ -78,6 +78,15 @@ namespace odb
struct image_traits<id_double> {typedef double image_type;};
template <>
+ struct image_traits<id_date> {typedef int image_type;};
+
+ template <>
+ struct image_traits<id_time> {typedef long long image_type;};
+
+ template <>
+ struct image_traits<id_timestamp> {typedef long long image_type;};
+
+ template <>
struct image_traits<id_string> {typedef details::buffer image_type;};
template <>
@@ -94,19 +103,6 @@ namespace odb
template <>
struct image_traits<id_uuid> {typedef unsigned char* image_type;};
- // @@ Date/time binary support in PostgreSQL is sketchy and in some
- // cases depends on server compile time constants. Using strings
- // to avoid this.
- //
- template <>
- struct image_traits<id_date> {typedef details::buffer image_type;};
-
- template <>
- struct image_traits<id_time> {typedef details::buffer image_type;};
-
- template <>
- struct image_traits<id_timestamp> {typedef details::buffer image_type;};
-
//
// value_traits
//