From f2a1bfb98f447e6c922c12f4403a387243dd65c5 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 3 Nov 2011 08:16:50 +0200 Subject: Add support for mapping std::vector to BLOB types --- odb/oracle/traits.cxx | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) (limited to 'odb/oracle/traits.cxx') diff --git a/odb/oracle/traits.cxx b/odb/oracle/traits.cxx index f9de006..40543ba 100644 --- a/odb/oracle/traits.cxx +++ b/odb/oracle/traits.cxx @@ -78,6 +78,28 @@ namespace odb } // + // default_value_traits, id_raw> + // + + void default_value_traits, id_raw>:: + set_image (char* b, + size_t c, + size_t& n, + bool& is_null, + const value_type& v) + { + is_null = false; + n = v.size (); + + assert (n <= c); + + // std::vector::data() may not be available in older compilers. + // + if (n != 0) + memcpy (b, &v.front (), n); + } + + // // string_lob_value_traits // @@ -149,6 +171,7 @@ namespace odb // // default_value_traits, id_blob> // + bool default_value_traits, id_blob>:: result_callback (void* c, void* b, ub4 s, chunk_position p) { @@ -193,5 +216,54 @@ namespace odb return true; } + + // + // default_value_traits, id_blob> + // + + bool default_value_traits, id_blob>:: + result_callback (void* c, void* b, ub4 s, chunk_position p) + { + value_type& v (*static_cast (c)); + + switch (p) + { + case one_chunk: + case first_chunk: + { + v.clear (); + + // Falling through. + } + case next_chunk: + case last_chunk: + { + unsigned char* cb (static_cast (b)); + v.insert (v.end (), cb, cb + s); + + break; + } + } + + return true; + } + + bool default_value_traits, id_blob>:: + param_callback (const void* ctx, + ub4*, + const void** b, + ub4* s, + chunk_position* p, + void*, + ub4) + { + const value_type& v (*static_cast (ctx)); + + *p = one_chunk; + *s = static_cast (v.size ()); + *b = &v.front (); + + return true; + } } } -- cgit v1.1