aboutsummaryrefslogtreecommitdiff
path: root/odb/oracle/traits.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2011-11-03 08:16:50 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2011-11-03 08:16:50 +0200
commitf2a1bfb98f447e6c922c12f4403a387243dd65c5 (patch)
treee4dd362e9d75571acc72f3885fe2f502ce4810ca /odb/oracle/traits.cxx
parent69547f193e980611262cc4569d3d6b19ba634fc4 (diff)
Add support for mapping std::vector<unsigned char> to BLOB types
Diffstat (limited to 'odb/oracle/traits.cxx')
-rw-r--r--odb/oracle/traits.cxx72
1 files changed, 72 insertions, 0 deletions
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<vector<unsigned char>, id_raw>
+ //
+
+ void default_value_traits<vector<unsigned char>, 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<std::vector<char>, id_blob>
//
+
bool default_value_traits<std::vector<char>, id_blob>::
result_callback (void* c, void* b, ub4 s, chunk_position p)
{
@@ -193,5 +216,54 @@ namespace odb
return true;
}
+
+ //
+ // default_value_traits<std::vector<unsigned char>, id_blob>
+ //
+
+ bool default_value_traits<std::vector<unsigned char>, id_blob>::
+ result_callback (void* c, void* b, ub4 s, chunk_position p)
+ {
+ value_type& v (*static_cast<value_type*> (c));
+
+ switch (p)
+ {
+ case one_chunk:
+ case first_chunk:
+ {
+ v.clear ();
+
+ // Falling through.
+ }
+ case next_chunk:
+ case last_chunk:
+ {
+ unsigned char* cb (static_cast<unsigned char*> (b));
+ v.insert (v.end (), cb, cb + s);
+
+ break;
+ }
+ }
+
+ return true;
+ }
+
+ bool default_value_traits<std::vector<unsigned char>, id_blob>::
+ param_callback (const void* ctx,
+ ub4*,
+ const void** b,
+ ub4* s,
+ chunk_position* p,
+ void*,
+ ub4)
+ {
+ const value_type& v (*static_cast<const value_type*> (ctx));
+
+ *p = one_chunk;
+ *s = static_cast<ub4> (v.size ());
+ *b = &v.front ();
+
+ return true;
+ }
}
}