From 26d4b0a333e327d7ef42c67db4c06918bafb1d84 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 21 Sep 2010 19:55:14 +0200 Subject: Redesign value_traits --- common/query/traits.hxx | 12 +++++----- mysql/types/traits.hxx | 61 +++++++++++++++++++++++-------------------------- 2 files changed, 34 insertions(+), 39 deletions(-) diff --git a/common/query/traits.hxx b/common/query/traits.hxx index 125929c..43b1bcc 100644 --- a/common/query/traits.hxx +++ b/common/query/traits.hxx @@ -17,20 +17,20 @@ namespace odb namespace mysql { template <> - class value_traits > + class value_traits, details::buffer> { public: - typedef std::auto_ptr type; - typedef std::string value_type; - static const image_id_type image_id = id_string; + typedef std::auto_ptr value_type; + typedef std::string query_type; + typedef details::buffer image_type; static void set_value (std::auto_ptr& v, - const char* s, + const details::buffer& b, std::size_t n, bool is_null) { - v.reset (is_null ? 0 : new std::string (s, n)); + v.reset (is_null ? 0 : new std::string (b.data (), n)); } static void diff --git a/mysql/types/traits.hxx b/mysql/types/traits.hxx index d113e7d..726135d 100644 --- a/mysql/types/traits.hxx +++ b/mysql/types/traits.hxx @@ -17,11 +17,12 @@ namespace odb namespace mysql { template <> - class value_traits + class value_traits { public: - typedef date_time type; typedef date_time value_type; + typedef date_time query_type; + typedef MYSQL_TIME image_type; static void set_value (date_time& v, const MYSQL_TIME& i, bool is_null) @@ -56,39 +57,26 @@ namespace odb }; template <> - class value_traits + class value_traits { public: - typedef buffer type; typedef buffer value_type; + typedef buffer query_type; + typedef details::buffer image_type; static void - set_value (buffer& v, const char* s, std::size_t n, bool is_null) + set_value (buffer& v, + const details::buffer& b, + std::size_t n, + bool is_null) { if (!is_null) - v.assign (s, n); + v.assign (b.data (), n); else v.assign (0, 0); } static void - set_image (char* s, - std::size_t c, - std::size_t& n, - bool& is_null, - const buffer& v) - { - is_null = false; - n = v.size (); - - if (n > c) - n = c; - - if (n != 0) - std::memcpy (s, v.data (), n); - } - - static void set_image (details::buffer& b, std::size_t& n, bool& is_null, @@ -106,11 +94,12 @@ namespace odb }; template <> - class value_traits + class value_traits { public: - typedef bitfield type; typedef bitfield value_type; + typedef bitfield query_type; + typedef unsigned char* image_type; static void set_value (bitfield& v, @@ -139,19 +128,24 @@ namespace odb }; template <> - class value_traits + class value_traits { public: - typedef set type; typedef set value_type; + typedef set query_type; + typedef details::buffer image_type; static void - set_value (set& v, const char* s, std::size_t n, bool is_null) + set_value (set& v, + const details::buffer& b, + std::size_t n, + bool is_null) { v.clear (); if (!is_null) { + const char* s (b.data ()); const char* e (s + n); while (s < e) @@ -196,19 +190,20 @@ namespace odb }; template <> - class value_traits > + class value_traits, details::buffer> { public: - typedef std::auto_ptr type; - typedef std::string value_type; + typedef std::auto_ptr value_type; + typedef std::string query_type; + typedef details::buffer image_type; static void set_value (std::auto_ptr& v, - const char* s, + const details::buffer& b, std::size_t n, bool is_null) { - v.reset (is_null ? 0 : new std::string (s, n)); + v.reset (is_null ? 0 : new std::string (b.data (), n)); } static void -- cgit v1.1