diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2011-11-03 10:11:24 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2011-11-03 10:11:24 +0200 |
commit | 2077828442e58677a2af1d15c6d5266455e50cad (patch) | |
tree | 5c96518d3c94eeede6b00fdb0cccef7b2551a092 | |
parent | 68f64ea9543f44b71f580f165bff52286e005c79 (diff) |
Add support for mapping char[N] and unsigned char[N] types to BLOB1.7.0.a1
New test: common/blob.
-rw-r--r-- | odb/mysql/traits.cxx | 2 | ||||
-rw-r--r-- | odb/mysql/traits.hxx | 77 |
2 files changed, 77 insertions, 2 deletions
diff --git a/odb/mysql/traits.cxx b/odb/mysql/traits.cxx index 0727861..382c638 100644 --- a/odb/mysql/traits.cxx +++ b/odb/mysql/traits.cxx @@ -3,8 +3,6 @@ // copyright : Copyright (c) 2005-2011 Code Synthesis Tools CC // license : GNU GPL v2; see accompanying LICENSE file -#include <cstring> // std::memcpy, std::strlen - #include <odb/mysql/traits.hxx> using namespace std; diff --git a/odb/mysql/traits.hxx b/odb/mysql/traits.hxx index 7994d59..8fdacb2 100644 --- a/odb/mysql/traits.hxx +++ b/odb/mysql/traits.hxx @@ -11,6 +11,7 @@ #include <string> #include <vector> #include <cstddef> // std::size_t +#include <cstring> // std::memcpy, std::memset, std::strlen #include <odb/traits.hxx> #include <odb/wrapper-traits.hxx> @@ -553,6 +554,82 @@ namespace odb const value_type&); }; + // char[n] (buffer) specialization. + // + template <std::size_t N> + struct default_value_traits<char[N], id_blob> + { + public: + typedef char* value_type; + typedef const char* query_type; + typedef details::buffer image_type; + + static void + set_value (char* const& v, + const details::buffer& b, + std::size_t n, + bool is_null) + { + if (!is_null) + std::memcpy (v, b.data (), (n < N ? n : N)); + else + std::memset (v, 0, N); + } + + static void + set_image (details::buffer& b, + std::size_t& n, + bool& is_null, + const char* v) + { + is_null = false; + n = N; + + if (n > b.capacity ()) + b.capacity (n); + + std::memcpy (b.data (), v, n); + } + }; + + // unsigned char[n] (buffer) specialization. + // + template <std::size_t N> + struct default_value_traits<unsigned char[N], id_blob> + { + public: + typedef unsigned char* value_type; + typedef const unsigned char* query_type; + typedef details::buffer image_type; + + static void + set_value (unsigned char* const& v, + const details::buffer& b, + std::size_t n, + bool is_null) + { + if (!is_null) + std::memcpy (v, b.data (), (n < N ? n : N)); + else + std::memset (v, 0, N); + } + + static void + set_image (details::buffer& b, + std::size_t& n, + bool& is_null, + const unsigned char* v) + { + is_null = false; + n = N; + + if (n > b.capacity ()) + b.capacity (n); + + std::memcpy (b.data (), v, n); + } + }; + // // type_traits // |