diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2011-11-03 10:11:24 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2011-11-03 10:11:24 +0200 |
commit | 60d4d13a85130ccdc3b232e420bc3c18683846b9 (patch) | |
tree | dfe5342529f87d9fb7d0b326951c52724032b703 | |
parent | a4dc2635e15ab4655b08b2e082404ec10e1655c3 (diff) |
Add support for mapping char[N] and unsigned char[N] types to BLOB1.7.0.a1
New test: common/blob.
-rw-r--r-- | odb/oracle/traits.cxx | 4 | ||||
-rw-r--r-- | odb/oracle/traits.hxx | 179 | ||||
-rw-r--r-- | odb/oracle/traits.txx | 70 |
3 files changed, 249 insertions, 4 deletions
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 <cstddef> // std::size_t -#include <cstring> // std::memcpy, std::strlen -#include <cassert> - #include <odb/oracle/traits.hxx> 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 <string> #include <vector> #include <cstddef> // std::size_t +#include <cstring> // std::memcpy, std::memset, std::strlen +#include <cassert> #include <odb/traits.hxx> #include <odb/wrapper-traits.hxx> @@ -632,6 +634,75 @@ namespace odb const value_type& v); }; + // char[n] (buffer) specialization for RAW. + // + template <std::size_t N> + struct default_value_traits<char[N], id_raw> + { + 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 <std::size_t N> + struct default_value_traits<unsigned char[N], id_raw> + { + 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 <std::size_t N> + struct default_value_traits<char[N], id_blob> + { + 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 <std::size_t N> + struct default_value_traits<unsigned char[N], id_blob> + { + 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 <odb/oracle/traits.txx> + #include <odb/post.hxx> #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 <constantin@codesynthesis.com> +// copyright : Copyright (c) 2005-2011 Code Synthesis Tools CC +// license : ODB NCUEL; see accompanying LICENSE file + +namespace odb +{ + namespace oracle + { + // + // default_value_traits<char[N], id_blob> + // + + template <std::size_t N> + bool default_value_traits<char[N], id_blob>:: + result_callback (void* c, ub4* position, void* b, ub4 s, chunk_position) + { + ub4 n (*position + s < N ? s : N - *position); + std::memcpy (static_cast<char*> (c) + *position, b, n); + *position += n; + return true; + } + + template <std::size_t N> + bool default_value_traits<char[N], id_blob>:: + param_callback (const void* c, + ub4*, + const void** b, + ub4* s, + chunk_position* p, + void*, + ub4) + { + *p = one_chunk; + *s = static_cast<ub4> (N); + *b = c; + return true; + } + + // + // default_value_traits<unsigned char[N], id_blob> + // + + template <std::size_t N> + bool default_value_traits<unsigned char[N], id_blob>:: + result_callback (void* c, ub4* position, void* b, ub4 s, chunk_position) + { + ub4 n (*position + s < N ? s : N - *position); + std::memcpy (static_cast<unsigned char*> (c) + *position, b, n); + *position += n; + return true; + } + + template <std::size_t N> + bool default_value_traits<unsigned char[N], id_blob>:: + param_callback (const void* c, + ub4*, + const void** b, + ub4* s, + chunk_position* p, + void*, + ub4) + { + *p = one_chunk; + *s = static_cast<ub4> (N); + *b = c; + return true; + } + } +} |