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.cxx | 4 -- odb/oracle/traits.hxx | 179 ++++++++++++++++++++++++++++++++++++++++++++++++++ odb/oracle/traits.txx | 70 ++++++++++++++++++++ 3 files changed, 249 insertions(+), 4 deletions(-) create mode 100644 odb/oracle/traits.txx diff --git a/odb/oracle/traits.cxx b/odb/oracle/traits.cxx index 22512ce..8b1ab34 100644 --- a/odb/oracle/traits.cxx +++ b/odb/oracle/traits.cxx @@ -3,10 +3,6 @@ // copyright : Copyright (c) 2005-2011 Code Synthesis Tools CC // license : ODB NCUEL; see accompanying LICENSE file -#include // std::size_t -#include // std::memcpy, std::strlen -#include - #include using namespace std; 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 diff --git a/odb/oracle/traits.txx b/odb/oracle/traits.txx new file mode 100644 index 0000000..86eab47 --- /dev/null +++ b/odb/oracle/traits.txx @@ -0,0 +1,70 @@ +// file : odb/oracle/traits.txx +// author : Constantin Michael +// copyright : Copyright (c) 2005-2011 Code Synthesis Tools CC +// license : ODB NCUEL; see accompanying LICENSE file + +namespace odb +{ + namespace oracle + { + // + // default_value_traits + // + + template + bool default_value_traits:: + result_callback (void* c, ub4* position, void* b, ub4 s, chunk_position) + { + ub4 n (*position + s < N ? s : N - *position); + std::memcpy (static_cast (c) + *position, b, n); + *position += n; + return true; + } + + template + bool default_value_traits:: + param_callback (const void* c, + ub4*, + const void** b, + ub4* s, + chunk_position* p, + void*, + ub4) + { + *p = one_chunk; + *s = static_cast (N); + *b = c; + return true; + } + + // + // default_value_traits + // + + template + bool default_value_traits:: + result_callback (void* c, ub4* position, void* b, ub4 s, chunk_position) + { + ub4 n (*position + s < N ? s : N - *position); + std::memcpy (static_cast (c) + *position, b, n); + *position += n; + return true; + } + + template + bool default_value_traits:: + param_callback (const void* c, + ub4*, + const void** b, + ub4* s, + chunk_position* p, + void*, + ub4) + { + *p = one_chunk; + *s = static_cast (N); + *b = c; + return true; + } + } +} -- cgit v1.1