aboutsummaryrefslogtreecommitdiff
path: root/odb/pgsql/traits.hxx
diff options
context:
space:
mode:
Diffstat (limited to 'odb/pgsql/traits.hxx')
-rw-r--r--odb/pgsql/traits.hxx77
1 files changed, 77 insertions, 0 deletions
diff --git a/odb/pgsql/traits.hxx b/odb/pgsql/traits.hxx
index 85a6af4..026e1d3 100644
--- a/odb/pgsql/traits.hxx
+++ b/odb/pgsql/traits.hxx
@@ -11,6 +11,7 @@
#include <string>
#include <vector>
#include <cstddef> // std::size_t
+#include <cstring> // std::memcpy, std::memset, std::strlen
#include <odb/traits.hxx>
#include <odb/wrapper-traits.hxx>
@@ -527,6 +528,82 @@ namespace odb
const value_type&);
};
+ // char[n] (buffer) specialization.
+ //
+ template <std::size_t N>
+ struct default_value_traits<char[N], id_bytea>
+ {
+ public:
+ typedef char* value_type;
+ typedef const char* query_type;
+ typedef details::buffer image_type;
+
+ static void
+ set_value (char* const& v,
+ const details::buffer& b,
+ std::size_t n,
+ bool is_null)
+ {
+ if (!is_null)
+ std::memcpy (v, b.data (), (n < N ? n : N));
+ else
+ std::memset (v, 0, N);
+ }
+
+ static void
+ set_image (details::buffer& b,
+ std::size_t& n,
+ bool& is_null,
+ const char* v)
+ {
+ is_null = false;
+ n = N;
+
+ if (n > b.capacity ())
+ b.capacity (n);
+
+ std::memcpy (b.data (), v, n);
+ }
+ };
+
+ // unsigned char[n] (buffer) specialization.
+ //
+ template <std::size_t N>
+ struct default_value_traits<unsigned char[N], id_bytea>
+ {
+ public:
+ typedef unsigned char* value_type;
+ typedef const unsigned char* query_type;
+ typedef details::buffer image_type;
+
+ static void
+ set_value (unsigned char* const& v,
+ const details::buffer& b,
+ std::size_t n,
+ bool is_null)
+ {
+ if (!is_null)
+ std::memcpy (v, b.data (), (n < N ? n : N));
+ else
+ std::memset (v, 0, N);
+ }
+
+ static void
+ set_image (details::buffer& b,
+ std::size_t& n,
+ bool& is_null,
+ const unsigned char* v)
+ {
+ is_null = false;
+ n = N;
+
+ if (n > b.capacity ())
+ b.capacity (n);
+
+ std::memcpy (b.data (), v, n);
+ }
+ };
+
//
// type_traits
//