From 877b93d4c98e21bababaca563ccb07ce26c56706 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 24 Jan 2013 15:10:22 +0200 Subject: Add support for mapping char[N] to CHAR/VARCHAR database types Also improve query support for arrays (decaying). --- odb/oracle/traits.hxx | 244 +++++++++++++++++++++++++++++--------------------- 1 file changed, 144 insertions(+), 100 deletions(-) (limited to 'odb/oracle/traits.hxx') diff --git a/odb/oracle/traits.hxx b/odb/oracle/traits.hxx index 2cbce04..13bb1dc 100644 --- a/odb/oracle/traits.hxx +++ b/odb/oracle/traits.hxx @@ -546,7 +546,7 @@ namespace odb { }; - // 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 @@ -577,45 +577,151 @@ namespace odb }; template <> + struct LIBODB_ORACLE_EXPORT default_value_traits: + c_string_value_traits {}; + + template <> + struct LIBODB_ORACLE_EXPORT default_value_traits: + c_string_value_traits {}; + + template <> struct LIBODB_ORACLE_EXPORT default_value_traits: - c_string_value_traits - { - typedef const char* query_type; - }; + c_string_value_traits {}; template <> struct LIBODB_ORACLE_EXPORT default_value_traits: - c_string_value_traits + c_string_value_traits {}; + + // char[N] specializations. + // + struct LIBODB_ORACLE_EXPORT c_array_value_traits_base { - typedef const char* query_type; + static void + set_value (char* const& v, + const char* b, + std::size_t n, + bool is_null, + std::size_t N); + + static void + set_image (char* b, + std::size_t c, + std::size_t& n, + bool& is_null, + const char* v, + std::size_t N); }; template - struct default_value_traits: c_string_value_traits + struct c_array_value_traits { + typedef char* value_type; typedef char query_type[N]; + typedef details::buffer image_type; + + static void + set_value (char* const& v, + const char* 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 (char* b, + std::size_t c, + std::size_t& n, + bool& is_null, + const char* v) + { + c_array_value_traits_base::set_image (b, c, n, is_null, v, N); + } }; template - struct default_value_traits: - c_string_value_traits - { - typedef const char query_type[N]; - }; + struct default_value_traits: + c_array_value_traits {}; template - struct default_value_traits: c_string_value_traits + struct default_value_traits: + c_array_value_traits {}; + + // std::array (string) specialization. + // +#ifdef ODB_CXX11 + template + struct std_array_value_traits { - typedef char query_type[N]; + typedef std::array value_type; + typedef std::array query_type; + typedef details::buffer image_type; + + static void + set_value (value_type& v, + const char* 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 (char* b, + std::size_t c, + std::size_t& n, + bool& is_null, + const value_type& v) + { + c_array_value_traits_base::set_image (b, c, n, is_null, v.data (), N); + } }; template - struct default_value_traits: - c_string_value_traits + struct default_value_traits, id_string>: + std_array_value_traits {}; + + template + struct default_value_traits, id_nstring>: + std_array_value_traits {}; +#endif + + // char specialization. + // + struct LIBODB_ORACLE_EXPORT char_value_traits { - typedef const char query_type[N]; + typedef char value_type; + typedef char query_type; + typedef details::buffer image_type; + + static void + set_value (char& v, + const char* 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 (char* b, + std::size_t c, + std::size_t& n, + bool& is_null, + char v) + { + c_array_value_traits_base::set_image (b, c, n, is_null, &v, 1); + } }; + template <> + struct LIBODB_ORACLE_EXPORT default_value_traits: + char_value_traits {}; + + template <> + struct LIBODB_ORACLE_EXPORT default_value_traits: + char_value_traits {}; + // std::vector (buffer) specialization for RAW. // template <> @@ -892,81 +998,6 @@ namespace odb { }; - // const char* specialization for LOBs. - // - // Specialization for const char* which only supports initialization - // of an image from the value but not the other way around. This way - // we can pass such values to the queries. - // - class LIBODB_ORACLE_EXPORT c_string_lob_value_traits - { - public: - typedef const char* value_type; - typedef lob_callback image_type; - - static void - set_image (param_callback_type& cb, - const void*& context, - bool& is_null, - const char* v) - { - is_null = false; - cb = ¶m_callback; - context = v; - } - - static bool - param_callback (const void* context, - ub4* position_context, - const void** buffer, - ub4* size, - chunk_position*, - void* temp_buffer, - ub4 capacity); - }; - - template <> - struct LIBODB_ORACLE_EXPORT default_value_traits: - c_string_lob_value_traits - { - typedef const char* query_type; - }; - - template <> - struct LIBODB_ORACLE_EXPORT default_value_traits: - c_string_lob_value_traits - { - typedef const char* query_type; - }; - - template - struct default_value_traits: - c_string_lob_value_traits - { - typedef char query_type[N]; - }; - - template - struct default_value_traits: - c_string_lob_value_traits - { - typedef const char query_type[N]; - }; - - template - struct default_value_traits: - c_string_lob_value_traits - { - typedef char query_type[N]; - }; - - template - struct default_value_traits: - c_string_lob_value_traits - { - typedef const char query_type[N]; - }; - // std::vector (buffer) specialization for BLOBs. // template <> @@ -1392,6 +1423,12 @@ namespace odb }; template <> + struct default_type_traits + { + static const database_type_id db_type_id = id_string; + }; + + template <> struct default_type_traits { static const database_type_id db_type_id = id_string; @@ -1403,37 +1440,44 @@ namespace odb static const database_type_id db_type_id = id_string; }; - template - struct default_type_traits + template <> + struct default_type_traits { static const database_type_id db_type_id = id_string; }; - // Binary types. Assume BLOB. + // Binary types. Assume RAW since LOBs cannot be compared in + // Oracle and this is only used in queries. // + template + struct default_type_traits + { + static const database_type_id db_type_id = id_raw; + }; + template <> struct default_type_traits > { - static const database_type_id db_type_id = id_blob; + static const database_type_id db_type_id = id_raw; }; template <> struct default_type_traits > { - static const database_type_id db_type_id = id_blob; + static const database_type_id db_type_id = id_raw; }; #ifdef ODB_CXX11 template struct default_type_traits > { - static const database_type_id db_type_id = id_blob; + static const database_type_id db_type_id = id_raw; }; template struct default_type_traits > { - static const database_type_id db_type_id = id_blob; + static const database_type_id db_type_id = id_raw; }; #endif } -- cgit v1.1