diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2011-07-28 09:45:36 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2011-07-28 09:45:36 +0200 |
commit | ab1487672afb5180bd17c9d26b35196bd06f6cda (patch) | |
tree | 51cc25e1b88cb0abc325a822f57845a98a22cb8a /sqlite | |
parent | a461f6d8bc6c314249057ad48fa8dd1cea1d8b40 (diff) |
Add value_traits specializations for std::vector<char>
This allows using it as a buffer for BLOB mapping.
Diffstat (limited to 'sqlite')
-rw-r--r-- | sqlite/types/driver.cxx | 4 | ||||
-rw-r--r-- | sqlite/types/test.hxx | 5 | ||||
-rw-r--r-- | sqlite/types/traits.hxx | 39 |
3 files changed, 5 insertions, 43 deletions
diff --git a/sqlite/types/driver.cxx b/sqlite/types/driver.cxx index 855cada..3c14c7a 100644 --- a/sqlite/types/driver.cxx +++ b/sqlite/types/driver.cxx @@ -13,6 +13,7 @@ #include <odb/sqlite/database.hxx> #include <odb/sqlite/transaction.hxx> +#include <common/buffer.hxx> #include <common/common.hxx> #include "test.hxx" @@ -35,10 +36,9 @@ main (int argc, char* argv[]) o.real_ = 1.123; string long_str (2040, 'l'); - buffer long_buf (long_str.c_str (), long_str.size ()); o.text_ = long_str; - o.blob_ = long_buf; + o.blob_.assign (long_str.c_str (), long_str.c_str () + long_str.size ()); { transaction t (db->begin ()); diff --git a/sqlite/types/test.hxx b/sqlite/types/test.hxx index 22cde8e..79b0a33 100644 --- a/sqlite/types/test.hxx +++ b/sqlite/types/test.hxx @@ -8,12 +8,11 @@ #include <set> #include <string> +#include <vector> #include <memory> // std::auto_ptr #include <odb/core.hxx> -#include <common/buffer.hxx> - typedef std::auto_ptr<std::string> string_ptr; #pragma db object @@ -44,7 +43,7 @@ struct object std::string text_; #pragma db type ("BLOB") - buffer blob_; + std::vector<char> blob_; // Test NULL value. // diff --git a/sqlite/types/traits.hxx b/sqlite/types/traits.hxx index 70b7b26..486e608 100644 --- a/sqlite/types/traits.hxx +++ b/sqlite/types/traits.hxx @@ -10,50 +10,13 @@ #include <odb/sqlite/traits.hxx> -#include "test.hxx" // buffer, string_ptr +#include "test.hxx" // string_ptr namespace odb { namespace sqlite { template <> - class value_traits<buffer, id_blob> - { - 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); - } - }; - - template <> class value_traits<string_ptr, id_text> { public: |