aboutsummaryrefslogtreecommitdiff
path: root/odb
diff options
context:
space:
mode:
authorConstantin Michael <constantin@codesynthesis.com>2011-07-14 09:53:29 +0200
committerConstantin Michael <constantin@codesynthesis.com>2011-07-14 09:53:29 +0200
commitdebdd3fa1bcf3c003636476484064ef919bc4d62 (patch)
tree2651d0aa01e6991b1e6fe66b7a9dd5c421313c5a /odb
parentdb26f79d8c2a367d6ed3b6ef91de29213f3430c7 (diff)
Add support for binary format NUMERIC type
Diffstat (limited to 'odb')
-rw-r--r--odb/pgsql/query.hxx80
-rw-r--r--odb/pgsql/statement.cxx133
2 files changed, 105 insertions, 108 deletions
diff --git a/odb/pgsql/query.hxx b/odb/pgsql/query.hxx
index 879517c..8ccc1f8 100644
--- a/odb/pgsql/query.hxx
+++ b/odb/pgsql/query.hxx
@@ -1267,44 +1267,50 @@ namespace odb
double image_;
};
- // @@ NUMERIC
+ // NUMERIC
//
- // template <typename T>
- // struct query_param_impl<T, id_numeric>: 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 ()
- // {
- // return init (*static_cast<const T*> (value_));
- // }
-
- // virtual void
- // bind (pgsql::bind* b)
- // {
- // b->type = bind::numeric;
- // b->buffer = buffer_.data ();
- // b->buffer_length = static_cast<unsigned long> (buffer_.capacity ());
- // b->length = &size_;
- // }
-
- // private:
- // bool
- // init (const T& v)
- // {
- // bool dummy;
- // std::size_t size, cap (buffer_.capacity ());
- // value_traits<T, id_decimal>::set_image (buffer_, size, dummy, v);
- // size_ = static_cast<unsigned long> (size);
- // return cap != buffer_.capacity ();
- // }
-
- // private:
- // details::buffer buffer_;
- // unsigned long size_;
- // };
+ template <typename T>
+ struct query_param_impl<T, id_numeric>: 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 ()
+ {
+ return init (*static_cast<const T*> (value_));
+ }
+
+ virtual void
+ bind (pgsql::bind* b)
+ {
+ b->type = bind::numeric;
+ b->buffer = buffer_.data ();
+ b->capacity = buffer_.capacity ();
+ b->size = &size_;
+ }
+
+ virtual unsigned int
+ oid () const
+ {
+ return numeric_oid;
+ }
+
+ private:
+ bool
+ init (const T& v)
+ {
+ bool dummy;
+ std::size_t size, cap (buffer_.capacity ());
+ value_traits<T, id_numeric>::set_image (buffer_, size, dummy, v);
+ size_ = size;
+ return cap != buffer_.capacity ();
+ }
+
+ private:
+ details::buffer buffer_;
+ std::size_t size_;
+ };
// DATE
//
diff --git a/odb/pgsql/statement.cxx b/odb/pgsql/statement.cxx
index cb49332..5b7a1da 100644
--- a/odb/pgsql/statement.cxx
+++ b/odb/pgsql/statement.cxx
@@ -13,6 +13,7 @@
#include <odb/pgsql/connection.hxx>
#include <odb/pgsql/transaction.hxx>
#include <odb/pgsql/error.hxx>
+
#include <odb/pgsql/details/endian-traits.hxx>
using namespace std;
@@ -88,82 +89,72 @@ namespace odb
}
n.values[i] = reinterpret_cast<char*> (current_bind.buffer);
+ n.formats[i] = 1;
- // Use text format for numeric types and binary format
- // for all others.
- //
- if (current_bind.type == bind::numeric)
- n.formats[i] = 0;
- else
- {
- n.formats[i] = 1;
-
- size_t l;
+ size_t l;
- switch (current_bind.type)
+ switch (current_bind.type)
+ {
+ case bind::boolean:
{
- case bind::boolean:
- {
- l = sizeof (bool);
- break;
- }
- case bind::smallint:
- {
- l = sizeof (short);
- break;
- }
- case bind::integer:
- {
- l = sizeof (int);
- break;
- }
- case bind::bigint:
- {
- l = sizeof (long long);
- break;
- }
- case bind::real:
- {
- l = sizeof (float);
- break;
- }
- case bind::double_:
- {
- 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.
- //
- l = 16;
- break;
- }
- case bind::text:
- case bind::bytea:
- case bind::bit:
- case bind::varbit:
- {
- l = *current_bind.size;
- break;
- }
- case bind::numeric:
- assert (false);
+ l = sizeof (bool);
+ break;
+ }
+ case bind::smallint:
+ {
+ l = sizeof (short);
+ break;
+ }
+ case bind::integer:
+ {
+ l = sizeof (int);
+ break;
+ }
+ case bind::bigint:
+ {
+ l = sizeof (long long);
+ break;
+ }
+ case bind::real:
+ {
+ l = sizeof (float);
+ break;
+ }
+ case bind::double_:
+ {
+ l = sizeof (double);
+ break;
+ }
+ case bind::date:
+ {
+ l = sizeof (int);
+ break;
+ }
+ case bind::time:
+ case bind::timestamp:
+ {
+ l = sizeof (long long);
+ break;
+ }
+ case bind::numeric:
+ case bind::text:
+ case bind::bytea:
+ case bind::bit:
+ case bind::varbit:
+ {
+ l = *current_bind.size;
+ break;
+ }
+ case bind::uuid:
+ {
+ // UUID is a 16-byte sequence.
+ //
+ l = 16;
+ break;
}
-
- n.lengths[i] = static_cast<int> (l);
}
+
+ n.lengths[i] = static_cast<int> (l);
}
}