diff options
Diffstat (limited to 'odb/pgsql/traits.hxx')
-rw-r--r-- | odb/pgsql/traits.hxx | 121 |
1 files changed, 112 insertions, 9 deletions
diff --git a/odb/pgsql/traits.hxx b/odb/pgsql/traits.hxx index 0267527..7983571 100644 --- a/odb/pgsql/traits.hxx +++ b/odb/pgsql/traits.hxx @@ -403,7 +403,7 @@ namespace odb const std::string&); }; - // const char* specialization + // char*/const char* specialization // // Specialization for const char* which only supports initialization // of an image from the value but not the other way around. This way @@ -423,23 +423,114 @@ namespace odb }; template <> + struct LIBODB_PGSQL_EXPORT default_value_traits<char*, id_string>: + c_string_value_traits {}; + + template <> struct LIBODB_PGSQL_EXPORT default_value_traits<const char*, id_string>: - c_string_value_traits + c_string_value_traits {}; + + // char[N] specializations. + // + struct LIBODB_PGSQL_EXPORT c_array_value_traits_base { - typedef const char* query_type; + static void + set_value (char* const& v, + const details::buffer& b, + std::size_t n, + bool is_null, + std::size_t N); + + static void + set_image (details::buffer& b, + std::size_t& n, + bool& is_null, + const char* v, + std::size_t N); }; template <std::size_t N> - struct default_value_traits<char[N], id_string>: c_string_value_traits + struct default_value_traits<char[N], id_string> { + typedef char* value_type; typedef char query_type[N]; + typedef details::buffer image_type; + + static void + set_value (char* const& v, + const details::buffer& b, + std::size_t n, + bool is_null) + { + c_array_value_traits_base::set_value (v, b, n, is_null, N); + } + + static void + set_image (details::buffer& b, + std::size_t& n, + bool& is_null, + const char* v) + { + c_array_value_traits_base::set_image (b, n, is_null, v, N); + } }; + // std::array<char, N> (string) specialization. + // +#ifdef ODB_CXX11 template <std::size_t N> - struct default_value_traits<const char[N], id_string>: - c_string_value_traits + struct default_value_traits<std::array<char, N>, id_string> { - typedef const char query_type[N]; + typedef std::array<char, N> value_type; + typedef std::array<char, N> 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) + { + c_array_value_traits_base::set_value (v.data (), b, n, is_null, N); + } + + static void + set_image (details::buffer& b, + std::size_t& n, + bool& is_null, + const value_type& v) + { + c_array_value_traits_base::set_image (b, n, is_null, v.data (), N); + } + }; +#endif + + // char specialization. + // + template <> + struct LIBODB_PGSQL_EXPORT default_value_traits<char, id_string> + { + typedef char value_type; + typedef char query_type; + typedef details::buffer image_type; + + static void + set_value (char& v, + const details::buffer& b, + std::size_t n, + bool is_null) + { + c_array_value_traits_base::set_value (&v, b, n, is_null, 1); + } + + static void + set_image (details::buffer& b, + std::size_t& n, + bool& is_null, + char v) + { + c_array_value_traits_base::set_image (b, n, is_null, &v, 1); + } }; // std::vector<char> (buffer) specialization. @@ -789,6 +880,12 @@ namespace odb }; template <> + struct default_type_traits<char*> + { + static const database_type_id db_type_id = id_string; + }; + + template <> struct default_type_traits<const char*> { static const database_type_id db_type_id = id_string; @@ -800,14 +897,20 @@ namespace odb static const database_type_id db_type_id = id_string; }; - template <std::size_t N> - struct default_type_traits<const char[N]> + template <> + struct default_type_traits<char> { static const database_type_id db_type_id = id_string; }; // Binary types. // + template <std::size_t N> + struct default_type_traits<unsigned char[N]> + { + static const database_type_id db_type_id = id_bytea; + }; + template <> struct default_type_traits<std::vector<char> > { |