aboutsummaryrefslogtreecommitdiff
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
commit0acb35c3ff7ce7e98fd6f3a92552558ec39f7c3d (patch)
tree6ec6be68d841e68b952a42a397213463d6f05803
parent6507a16de2e1e3d0a5432b37ada08baf4af3b790 (diff)
Add support for mapping std::vector<unsigned char> to BLOB types
-rw-r--r--odb/pgsql/traits.cxx22
-rw-r--r--odb/pgsql/traits.hxx37
2 files changed, 58 insertions, 1 deletions
diff --git a/odb/pgsql/traits.cxx b/odb/pgsql/traits.cxx
index a2c2f2f..9e31c9f 100644
--- a/odb/pgsql/traits.cxx
+++ b/odb/pgsql/traits.cxx
@@ -76,5 +76,27 @@ namespace odb
if (n != 0)
memcpy (b.data (), &v.front (), n);
}
+
+ //
+ // default_value_traits<vector<unsigned char>, id_bytea>
+ //
+
+ void default_value_traits<vector<unsigned char>, id_bytea>::
+ set_image (details::buffer& b,
+ size_t& n,
+ bool& is_null,
+ const value_type& v)
+ {
+ is_null = false;
+ n = v.size ();
+
+ if (n > b.capacity ())
+ b.capacity (n);
+
+ // std::vector::data() may not be available in older compilers.
+ //
+ if (n != 0)
+ memcpy (b.data (), &v.front (), n);
+ }
}
}
diff --git a/odb/pgsql/traits.hxx b/odb/pgsql/traits.hxx
index b4b6a11..85a6af4 100644
--- a/odb/pgsql/traits.hxx
+++ b/odb/pgsql/traits.hxx
@@ -466,7 +466,8 @@ namespace odb
// std::vector<char> (buffer) specialization.
//
template <>
- struct LIBODB_PGSQL_EXPORT default_value_traits<std::vector<char>, id_bytea>
+ struct LIBODB_PGSQL_EXPORT default_value_traits<
+ std::vector<char>, id_bytea>
{
public:
typedef std::vector<char> value_type;
@@ -492,6 +493,40 @@ namespace odb
const value_type&);
};
+ // std::vector<unsigned char> (buffer) specialization.
+ //
+ template <>
+ struct LIBODB_PGSQL_EXPORT default_value_traits<
+ std::vector<unsigned char>, id_bytea>
+ {
+ public:
+ typedef std::vector<unsigned char> value_type;
+ typedef std::vector<unsigned char> query_type;
+ typedef details::buffer image_type;
+
+ static void
+ set_value (value_type& v,
+ const details::buffer& b,
+ std::size_t n,
+ bool is_null)
+ {
+ if (!is_null)
+ {
+ const unsigned char* d (
+ reinterpret_cast<const unsigned char*> (b.data ()));
+ v.assign (d, d + n);
+ }
+ else
+ v.clear ();
+ }
+
+ static void
+ set_image (details::buffer&,
+ std::size_t& n,
+ bool& is_null,
+ const value_type&);
+ };
+
//
// type_traits
//