diff options
-rw-r--r-- | odb/sqlite/query.hxx | 10 | ||||
-rw-r--r-- | odb/sqlite/traits.cxx | 4 | ||||
-rw-r--r-- | odb/sqlite/traits.hxx | 41 |
3 files changed, 35 insertions, 20 deletions
diff --git a/odb/sqlite/query.hxx b/odb/sqlite/query.hxx index edf9222..98189ab 100644 --- a/odb/sqlite/query.hxx +++ b/odb/sqlite/query.hxx @@ -1059,7 +1059,7 @@ namespace odb init (const T& v) { bool dummy; - value_traits<T, long long, id_integer>::set_image (image_, dummy, v); + value_traits<T, id_integer>::set_image (image_, dummy, v); } private: @@ -1093,7 +1093,7 @@ namespace odb init (const T& v) { bool dummy; - value_traits<T, double, id_real>::set_image (image_, dummy, v); + value_traits<T, id_real>::set_image (image_, dummy, v); } private: @@ -1128,8 +1128,7 @@ namespace odb { bool dummy; std::size_t cap (buffer_.capacity ()); - value_traits<T, details::buffer, id_text>::set_image ( - buffer_, size_, dummy, v); + value_traits<T, id_text>::set_image (buffer_, size_, dummy, v); return cap != buffer_.capacity (); } @@ -1166,8 +1165,7 @@ namespace odb { bool dummy; std::size_t cap (buffer_.capacity ()); - value_traits<T, details::buffer, id_blob>::set_image ( - buffer_, size_, dummy, v); + value_traits<T, id_blob>::set_image (buffer_, size_, dummy, v); return cap != buffer_.capacity (); } diff --git a/odb/sqlite/traits.cxx b/odb/sqlite/traits.cxx index de6c792..e73462a 100644 --- a/odb/sqlite/traits.cxx +++ b/odb/sqlite/traits.cxx @@ -17,7 +17,7 @@ namespace odb // default_value_traits<std::string> // - void default_value_traits<string, buffer, id_text>:: + void default_value_traits<string, id_text>:: set_image (buffer& b, size_t& n, bool& is_null, @@ -35,7 +35,7 @@ namespace odb // default_value_traits<const char*> // - void default_value_traits<const char*, buffer, id_text>:: + void default_value_traits<const char*, id_text>:: set_image (buffer& b, size_t& n, bool& is_null, diff --git a/odb/sqlite/traits.hxx b/odb/sqlite/traits.hxx index e5ef318..2fdac04 100644 --- a/odb/sqlite/traits.hxx +++ b/odb/sqlite/traits.hxx @@ -30,26 +30,45 @@ namespace odb }; // + // image_traits + // + + template <database_type_id> + struct image_traits; + + template <> + struct image_traits<id_integer> {typedef long long image_type;}; + + template <> + struct image_traits<id_real> {typedef double image_type;}; + + template <> + struct image_traits<id_text> {typedef details::buffer image_type;}; + + template <> + struct image_traits<id_blob> {typedef details::buffer image_type;}; + + // // value_traits // - template <typename T, typename I, database_type_id> + template <typename T, database_type_id> struct default_value_traits; - template <typename T, typename I, database_type_id ID> - class value_traits: public default_value_traits<T, I, ID> + template <typename T, database_type_id ID> + class value_traits: public default_value_traits<T, ID> { }; - template <typename T, typename I, database_type_id> + template <typename T, database_type_id ID> struct default_value_traits { typedef T value_type; typedef T query_type; - typedef I image_type; + typedef typename image_traits<ID>::image_type image_type; static void - set_value (T& v, I i, bool is_null) + set_value (T& v, const image_type& i, bool is_null) { if (!is_null) v = T (i); @@ -58,18 +77,17 @@ namespace odb } static void - set_image (I& i, bool& is_null, T v) + set_image (image_type& i, bool& is_null, T v) { is_null = false; - i = I (v); + i = image_type (v); } }; // std::string specialization. // template <> - struct LIBODB_SQLITE_EXPORT default_value_traits< - std::string, details::buffer, id_text> + struct LIBODB_SQLITE_EXPORT default_value_traits<std::string, id_text> { typedef std::string value_type; typedef std::string query_type; @@ -101,8 +119,7 @@ namespace odb // we can pass such values to the queries. // template <> - struct LIBODB_SQLITE_EXPORT default_value_traits< - const char*, details::buffer, id_text> + struct LIBODB_SQLITE_EXPORT default_value_traits<const char*, id_text> { typedef const char* value_type; typedef const char* query_type; |