From 60d4d13a85130ccdc3b232e420bc3c18683846b9 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 3 Nov 2011 10:11:24 +0200 Subject: Add support for mapping char[N] and unsigned char[N] types to BLOB New test: common/blob. --- odb/oracle/traits.hxx | 179 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 179 insertions(+) (limited to 'odb/oracle/traits.hxx') diff --git a/odb/oracle/traits.hxx b/odb/oracle/traits.hxx index ded74c9..e8c3ec2 100644 --- a/odb/oracle/traits.hxx +++ b/odb/oracle/traits.hxx @@ -11,6 +11,8 @@ #include #include #include // std::size_t +#include // std::memcpy, std::memset, std::strlen +#include #include #include @@ -632,6 +634,75 @@ namespace odb const value_type& v); }; + // char[n] (buffer) specialization for RAW. + // + template + struct default_value_traits + { + public: + typedef char* value_type; + typedef const char* query_type; + typedef char* image_type; + + static void + set_value (char* const& v, const char* b, std::size_t n, bool is_null) + { + if (!is_null) + std::memcpy (v, b, (n < N ? n : N)); + else + std::memset (v, 0, N); + } + + static void + set_image (char* b, + std::size_t c, + std::size_t& n, + bool& is_null, + const char* v) + { + is_null = false; + n = N; + assert (N <= c); + std::memcpy (b, v, n); + } + }; + + // unsigned char[n] (buffer) specialization for RAW. + // + template + struct default_value_traits + { + public: + typedef unsigned char* value_type; + typedef const unsigned char* query_type; + typedef char* image_type; + + static void + set_value (unsigned char* const& v, + const char* b, + std::size_t n, + bool is_null) + { + if (!is_null) + std::memcpy (v, b, (n < N ? n : N)); + else + std::memset (v, 0, N); + } + + static void + set_image (char* b, + std::size_t c, + std::size_t& n, + bool& is_null, + const unsigned char* v) + { + is_null = false; + n = N; + assert (N <= c); + std::memcpy (b, v, n); + } + }; + // std::string specialization for LOBs. // class string_lob_value_traits @@ -872,6 +943,112 @@ namespace odb ub4 capacity); }; + // char[n] (buffer) specialization for BLOBs. + // + template + struct default_value_traits + { + public: + typedef char* value_type; + typedef const char* query_type; + typedef lob_callback image_type; + + static void + set_value (char* const& v, + result_callback_type& cb, + void*& context, + bool is_null) + { + if (!is_null) + { + cb = &result_callback; + context = v; + } + else + std::memset (v, 0, N); + } + + 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 + result_callback (void* context, + ub4* position_context, + void* buffer, + ub4 size, + chunk_position); + + static bool + param_callback (const void* context, + ub4* position_context, + const void** buffer, + ub4* size, + chunk_position*, + void* temp_buffer, + ub4 capacity); + }; + + // unsigned char[n] (buffer) specialization for BLOBs. + // + template + struct default_value_traits + { + public: + typedef unsigned char* value_type; + typedef const unsigned char* query_type; + typedef lob_callback image_type; + + static void + set_value (unsigned char* const& v, + result_callback_type& cb, + void*& context, + bool is_null) + { + if (!is_null) + { + cb = &result_callback; + context = v; + } + else + std::memset (v, 0, N); + } + + static void + set_image (param_callback_type& cb, + const void*& context, + bool& is_null, + const unsigned char* v) + { + is_null = false; + cb = ¶m_callback; + context = v; + } + + static bool + result_callback (void* context, + ub4* position_context, + void* buffer, + ub4 size, + chunk_position); + + static bool + param_callback (const void* context, + ub4* position_context, + const void** buffer, + ub4* size, + chunk_position*, + void* temp_buffer, + ub4 capacity); + }; + // // type_traits // @@ -994,6 +1171,8 @@ namespace odb } } +#include + #include #endif // ODB_ORACLE_TRAITS_HXX -- cgit v1.1