From debdd3fa1bcf3c003636476484064ef919bc4d62 Mon Sep 17 00:00:00 2001 From: Constantin Michael Date: Thu, 14 Jul 2011 09:53:29 +0200 Subject: Add support for binary format NUMERIC type --- odb/pgsql/query.hxx | 80 +++++++++++++++-------------- odb/pgsql/statement.cxx | 133 ++++++++++++++++++++++-------------------------- 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 - // struct query_param_impl: query_param - // { - // query_param_impl (ref_bind r) : query_param (&r.ref) {} - // query_param_impl (val_bind v) : query_param (0) {init (v.val);} - - // virtual bool - // init () - // { - // return init (*static_cast (value_)); - // } - - // virtual void - // bind (pgsql::bind* b) - // { - // b->type = bind::numeric; - // b->buffer = buffer_.data (); - // b->buffer_length = static_cast (buffer_.capacity ()); - // b->length = &size_; - // } - - // private: - // bool - // init (const T& v) - // { - // bool dummy; - // std::size_t size, cap (buffer_.capacity ()); - // value_traits::set_image (buffer_, size, dummy, v); - // size_ = static_cast (size); - // return cap != buffer_.capacity (); - // } - - // private: - // details::buffer buffer_; - // unsigned long size_; - // }; + template + struct query_param_impl: query_param + { + query_param_impl (ref_bind r) : query_param (&r.ref) {} + query_param_impl (val_bind v) : query_param (0) {init (v.val);} + + virtual bool + init () + { + return init (*static_cast (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::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 #include #include + #include using namespace std; @@ -88,82 +89,72 @@ namespace odb } n.values[i] = reinterpret_cast (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 (l); } + + n.lengths[i] = static_cast (l); } } -- cgit v1.1