diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2011-11-03 08:16:50 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2011-11-03 08:16:50 +0200 |
commit | f2a1bfb98f447e6c922c12f4403a387243dd65c5 (patch) | |
tree | e4dd362e9d75571acc72f3885fe2f502ce4810ca /odb/oracle/traits.hxx | |
parent | 69547f193e980611262cc4569d3d6b19ba634fc4 (diff) |
Add support for mapping std::vector<unsigned char> to BLOB types
Diffstat (limited to 'odb/oracle/traits.hxx')
-rw-r--r-- | odb/oracle/traits.hxx | 81 |
1 files changed, 80 insertions, 1 deletions
diff --git a/odb/oracle/traits.hxx b/odb/oracle/traits.hxx index bcad915..edaeebf 100644 --- a/odb/oracle/traits.hxx +++ b/odb/oracle/traits.hxx @@ -575,7 +575,7 @@ namespace odb { }; - // std::vector specialization for RAW. + // std::vector<char> (buffer) specialization for RAW. // template <> struct default_value_traits<std::vector<char>, id_raw> @@ -602,6 +602,36 @@ namespace odb const value_type& v); }; + // std::vector<unsigned char> (buffer) specialization for RAW. + // + template <> + struct default_value_traits<std::vector<unsigned char>, id_raw> + { + public: + typedef std::vector<unsigned char> value_type; + typedef std::vector<unsigned char> query_type; + typedef lob_callback image_type; + + static void + set_value (value_type& v, const char* b, std::size_t n, bool is_null) + { + if (!is_null) + { + const unsigned char* ub (reinterpret_cast<const unsigned char*> (b)); + v.assign (ub, ub + n); + } + else + v.clear (); + } + + static void + set_image (char* b, + std::size_t c, + std::size_t& n, + bool& is_null, + const value_type& v); + }; + // std::string specialization for LOBs. // class string_lob_value_traits @@ -781,6 +811,55 @@ namespace odb ub4 capacity); }; + // std::vector<unsigned char> (buffer) specialization for BLOBs. + // + template <> + struct default_value_traits<std::vector<unsigned char>, id_blob> + { + public: + typedef std::vector<unsigned char> value_type; + typedef std::vector<unsigned char> query_type; + typedef lob_callback image_type; + + static void + set_value (value_type& v, + result_callback_type& cb, + void*& context, + bool is_null) + { + if (!is_null) + { + cb = &result_callback; + context = &v; + } + else + v.clear (); + } + + static void + set_image (param_callback_type& cb, + const void*& context, + bool& is_null, + const value_type& v) + { + is_null = false; + cb = ¶m_callback; + context = &v; + } + + static bool + result_callback (void* 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 // |