aboutsummaryrefslogtreecommitdiff
path: root/odb/mysql/traits.hxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2010-07-30 13:24:51 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2010-07-30 13:24:51 +0200
commit861857508074a0bd8ebafd51007d9c0662b07101 (patch)
treefe85c030081acea040ced6a4ba479cf03c8bf4b4 /odb/mysql/traits.hxx
parent57ef48552e7d855151bac235a9f1af21255c8474 (diff)
Add MySQL-specific value traits
Diffstat (limited to 'odb/mysql/traits.hxx')
-rw-r--r--odb/mysql/traits.hxx74
1 files changed, 74 insertions, 0 deletions
diff --git a/odb/mysql/traits.hxx b/odb/mysql/traits.hxx
new file mode 100644
index 0000000..18aeac5
--- /dev/null
+++ b/odb/mysql/traits.hxx
@@ -0,0 +1,74 @@
+// file : odb/mysql/traits.hxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef ODB_MYSQL_TRAITS_HXX
+#define ODB_MYSQL_TRAITS_HXX
+
+#include <string>
+#include <cstddef> // std::size_t
+#include <cstring> // std::memcpy
+
+#include <odb/traits.hxx>
+
+namespace odb
+{
+ namespace mysql
+ {
+ template <typename T>
+ struct value_traits: odb::value_traits<T>
+ {
+ };
+
+ template <>
+ struct value_traits<std::string>
+ {
+ typedef std::string value_type;
+
+ static void
+ set_value (value_type& v, const char* s, std::size_t n, bool is_null)
+ {
+ if (!is_null)
+ v.assign (s, n);
+ else
+ v.erase ();
+ }
+
+ static void
+ set_image (char* s,
+ std::size_t c,
+ std::size_t& n,
+ bool& is_null,
+ const value_type& v)
+ {
+ is_null = false;
+ n = v.size ();
+
+ if (n > c)
+ n = c;
+
+ if (n != 0)
+ std::memcpy (s, v.c_str (), n);
+ }
+
+ static void
+ set_image (buffer& b,
+ std::size_t& n,
+ bool& is_null,
+ const value_type& v)
+ {
+ is_null = false;
+ n = v.size ();
+
+ if (n > b.capacity ())
+ b.capacity (n);
+
+ if (n != 0)
+ std::memcpy (b.data (), v.c_str (), n);
+ }
+ };
+ }
+}
+
+#endif // ODB_MYSQL_TRAITS_HXX