diff options
-rw-r--r-- | odb/mysql/traits.cxx | 22 | ||||
-rw-r--r-- | odb/mysql/traits.hxx | 30 |
2 files changed, 52 insertions, 0 deletions
diff --git a/odb/mysql/traits.cxx b/odb/mysql/traits.cxx index c0686b5..38cffa8 100644 --- a/odb/mysql/traits.cxx +++ b/odb/mysql/traits.cxx @@ -54,5 +54,27 @@ namespace odb if (n != 0) memcpy (b.data (), v, n); } + + // + // default_value_traits<vector<char>, id_blob> + // + + void default_value_traits<vector<char>, id_blob>:: + set_image (details::buffer& b, + size_t& n, + bool& is_null, + const value_type& v) + { + is_null = false; + n = v.size (); + + if (n > b.capacity ()) + b.capacity (n); + + // std::vector::data() may not be available in older compilers. + // + if (n != 0) + memcpy (b.data (), &v[0], n); + } } } diff --git a/odb/mysql/traits.hxx b/odb/mysql/traits.hxx index 7f96c0b..b5c9830 100644 --- a/odb/mysql/traits.hxx +++ b/odb/mysql/traits.hxx @@ -9,6 +9,7 @@ #include <odb/pre.hxx> #include <string> +#include <vector> #include <cstddef> // std::size_t #include <odb/traits.hxx> @@ -289,6 +290,35 @@ namespace odb { }; + // std::vector<char> (buffer) specialization. + // + template <> + struct LIBODB_MYSQL_EXPORT default_value_traits<std::vector<char>, id_blob> + { + public: + typedef std::vector<char> value_type; + typedef std::vector<char> query_type; + typedef details::buffer image_type; + + static void + set_value (value_type& v, + const details::buffer& b, + std::size_t n, + bool is_null) + { + if (!is_null) + v.assign (b.data (), b.data () + n); + else + v.clear (); + } + + static void + set_image (details::buffer&, + std::size_t& n, + bool& is_null, + const value_type&); + }; + // // type_traits // |