diff options
Diffstat (limited to 'odb/mysql/traits.hxx')
-rw-r--r-- | odb/mysql/traits.hxx | 121 |
1 files changed, 97 insertions, 24 deletions
diff --git a/odb/mysql/traits.hxx b/odb/mysql/traits.hxx index 63673ff..5418fa1 100644 --- a/odb/mysql/traits.hxx +++ b/odb/mysql/traits.hxx @@ -54,26 +54,99 @@ namespace odb }; // + // image_traits + // + + template <database_type_id> + struct image_traits; + + template <> + struct image_traits<id_tiny> {typedef signed char image_type;}; + + template <> + struct image_traits<id_utiny> {typedef unsigned char image_type;}; + + template <> + struct image_traits<id_short> {typedef short image_type;}; + + template <> + struct image_traits<id_ushort> {typedef unsigned short image_type;}; + + template <> + struct image_traits<id_long> {typedef int image_type;}; + + template <> + struct image_traits<id_ulong> {typedef unsigned int image_type;}; + + template <> + struct image_traits<id_longlong> {typedef long long image_type;}; + + template <> + struct image_traits<id_ulonglong> {typedef unsigned long long image_type;}; + + template <> + struct image_traits<id_float> {typedef float image_type;}; + + template <> + struct image_traits<id_double> {typedef double image_type;}; + + template <> + struct image_traits<id_decimal> {typedef details::buffer image_type;}; + + template <> + struct image_traits<id_date> {typedef MYSQL_TIME image_type;}; + + template <> + struct image_traits<id_time> {typedef MYSQL_TIME image_type;}; + + template <> + struct image_traits<id_datetime> {typedef MYSQL_TIME image_type;}; + + template <> + struct image_traits<id_timestamp> {typedef MYSQL_TIME image_type;}; + + template <> + struct image_traits<id_year> {typedef short image_type;}; + + template <> + struct image_traits<id_string> {typedef details::buffer image_type;}; + + template <> + struct image_traits<id_blob> {typedef details::buffer image_type;}; + + template <> + struct image_traits<id_bit> {typedef unsigned char* image_type;}; + + // Note: default mapping is to integer. Alternative mapping is to + // string. + // + template <> + struct image_traits<id_enum> {typedef unsigned short image_type;}; + + template <> + struct image_traits<id_set> {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); @@ -82,10 +155,10 @@ 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); } }; @@ -118,26 +191,26 @@ namespace odb }; template <> - struct LIBODB_MYSQL_EXPORT default_value_traits< - std::string, details::buffer, id_string>: string_value_traits + struct LIBODB_MYSQL_EXPORT default_value_traits<std::string, id_string>: + string_value_traits { }; template <> - struct LIBODB_MYSQL_EXPORT default_value_traits< - std::string, details::buffer, id_decimal>: string_value_traits + struct LIBODB_MYSQL_EXPORT default_value_traits<std::string, id_decimal>: + string_value_traits { }; template <> - struct LIBODB_MYSQL_EXPORT default_value_traits< - std::string, details::buffer, id_enum>: string_value_traits + struct LIBODB_MYSQL_EXPORT default_value_traits<std::string, id_enum>: + string_value_traits { }; template <> - struct LIBODB_MYSQL_EXPORT default_value_traits< - std::string, details::buffer, id_set>: string_value_traits + struct LIBODB_MYSQL_EXPORT default_value_traits<std::string, id_set>: + string_value_traits { }; @@ -162,26 +235,26 @@ namespace odb }; template <> - struct LIBODB_MYSQL_EXPORT default_value_traits< - const char*, details::buffer, id_string>: c_string_value_traits + struct LIBODB_MYSQL_EXPORT default_value_traits<const char*, id_string>: + c_string_value_traits { }; template <> - struct LIBODB_MYSQL_EXPORT default_value_traits< - const char*, details::buffer, id_decimal>: c_string_value_traits + struct LIBODB_MYSQL_EXPORT default_value_traits<const char*, id_decimal>: + c_string_value_traits { }; template <> - struct LIBODB_MYSQL_EXPORT default_value_traits< - const char*, details::buffer, id_enum>: c_string_value_traits + struct LIBODB_MYSQL_EXPORT default_value_traits<const char*, id_enum>: + c_string_value_traits { }; template <> - struct LIBODB_MYSQL_EXPORT default_value_traits< - const char*, details::buffer, id_set>: c_string_value_traits + struct LIBODB_MYSQL_EXPORT default_value_traits<const char*, id_set>: + c_string_value_traits { }; |