aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--odb/sqlite/traits.cxx2
-rw-r--r--odb/sqlite/traits.hxx77
2 files changed, 77 insertions, 2 deletions
diff --git a/odb/sqlite/traits.cxx b/odb/sqlite/traits.cxx
index d6b6572..3884f36 100644
--- a/odb/sqlite/traits.cxx
+++ b/odb/sqlite/traits.cxx
@@ -3,8 +3,6 @@
// copyright : Copyright (c) 2005-2011 Code Synthesis Tools CC
// license : GNU GPL v2; see accompanying LICENSE file
-#include <cstring> // std::memcpy, std::strlen
-
#include <odb/sqlite/traits.hxx>
using namespace std;
diff --git a/odb/sqlite/traits.hxx b/odb/sqlite/traits.hxx
index b53d3ab..fe16835 100644
--- a/odb/sqlite/traits.hxx
+++ b/odb/sqlite/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>
@@ -329,6 +330,82 @@ namespace odb
const value_type&);
};
+ // char[n] (buffer) specialization.
+ //
+ template <std::size_t N>
+ struct default_value_traits<char[N], id_blob>
+ {
+ 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_blob>
+ {
+ 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
//