From ab1487672afb5180bd17c9d26b35196bd06f6cda Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 28 Jul 2011 09:45:36 +0200 Subject: Add value_traits specializations for std::vector This allows using it as a buffer for BLOB mapping. --- pgsql/types/driver.cxx | 3 +-- pgsql/types/test.hxx | 3 ++- pgsql/types/traits.hxx | 39 +-------------------------------------- 3 files changed, 4 insertions(+), 41 deletions(-) (limited to 'pgsql') diff --git a/pgsql/types/driver.cxx b/pgsql/types/driver.cxx index 745d2ee..d6d675c 100644 --- a/pgsql/types/driver.cxx +++ b/pgsql/types/driver.cxx @@ -51,8 +51,7 @@ main (int argc, char* argv[]) o.varchar_ = medium_str; o.text_ = long_str; - buffer long_buf (long_str.c_str (), long_str.size ()); - o.bytea_ = long_buf; + o.bytea_.assign (long_str.c_str (), long_str.c_str () + long_str.size ()); unsigned char varbit_buf[8] = {1, 3, 1, 3, 1, 3, 1, 3}; o.varbit_.size = 52; diff --git a/pgsql/types/test.hxx b/pgsql/types/test.hxx index 48c30ee..500887a 100644 --- a/pgsql/types/test.hxx +++ b/pgsql/types/test.hxx @@ -8,6 +8,7 @@ #include #include +#include #include // std::auto_ptr #include // std::memcmp #include // std::size_t @@ -139,7 +140,7 @@ struct object std::string text_; #pragma db type ("BYTEA") - buffer bytea_; + std::vector bytea_; #pragma db type ("VARBIT(1024)") varbit varbit_; diff --git a/pgsql/types/traits.hxx b/pgsql/types/traits.hxx index b3aec70..9852727 100644 --- a/pgsql/types/traits.hxx +++ b/pgsql/types/traits.hxx @@ -12,49 +12,12 @@ #include #include -#include "test.hxx" // varbit, buffer, ubuffer, string_ptr +#include "test.hxx" // varbit, ubuffer, string_ptr namespace odb { namespace pgsql { - template <> - class value_traits - { - public: - typedef buffer value_type; - typedef buffer query_type; - typedef details::buffer image_type; - - static void - set_value (buffer& v, - const details::buffer& b, - std::size_t n, - bool is_null) - { - if (!is_null) - v.assign (b.data (), n); - else - v.assign (0, 0); - } - - static void - set_image (details::buffer& b, - std::size_t& n, - bool& is_null, - const buffer& v) - { - is_null = false; - n = v.size (); - - if (n > b.capacity ()) - b.capacity (n); - - if (n != 0) - std::memcpy (b.data (), v.data (), n); - } - }; - // The first 4 bytes of the image is a signed int specifying the // number of significant bits contained by the BIT. The following // bytes contain the bit data. -- cgit v1.1