aboutsummaryrefslogtreecommitdiff
path: root/odb/sqlite/traits.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2011-03-22 15:48:14 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2011-03-22 15:49:23 +0200
commitb1a6710e7d396538617550f1d00b4db2575485c7 (patch)
treefa750a09513e3626ada8233d125322f631f9d1d1 /odb/sqlite/traits.cxx
parent4a4762c4b8e945dd617034a40f6633e0c9f364c7 (diff)
Implement built-in value traits for SQLite
Diffstat (limited to 'odb/sqlite/traits.cxx')
-rw-r--r--odb/sqlite/traits.cxx54
1 files changed, 54 insertions, 0 deletions
diff --git a/odb/sqlite/traits.cxx b/odb/sqlite/traits.cxx
new file mode 100644
index 0000000..de6c792
--- /dev/null
+++ b/odb/sqlite/traits.cxx
@@ -0,0 +1,54 @@
+// file : odb/sqlite/traits.cxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// 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;
+
+namespace odb
+{
+ namespace sqlite
+ {
+ using details::buffer;
+
+ // default_value_traits<std::string>
+ //
+ void default_value_traits<string, buffer, id_text>::
+ set_image (buffer& b,
+ size_t& n,
+ bool& is_null,
+ const string& v)
+ {
+ is_null = false;
+ n = v.size ();
+
+ if (n > b.capacity ())
+ b.capacity (n);
+
+ if (n != 0)
+ memcpy (b.data (), v.c_str (), n);
+ }
+
+ // default_value_traits<const char*>
+ //
+ void default_value_traits<const char*, buffer, id_text>::
+ set_image (buffer& b,
+ size_t& n,
+ bool& is_null,
+ const char* v)
+ {
+ is_null = false;
+ n = strlen (v);
+
+ if (n > b.capacity ())
+ b.capacity (n);
+
+ if (n != 0)
+ memcpy (b.data (), v, n);
+ }
+ }
+}