From 861857508074a0bd8ebafd51007d9c0662b07101 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 30 Jul 2010 13:24:51 +0200 Subject: Add MySQL-specific value traits --- odb/mysql/traits.hxx | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 odb/mysql/traits.hxx 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 +// 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 +#include // std::size_t +#include // std::memcpy + +#include + +namespace odb +{ + namespace mysql + { + template + struct value_traits: odb::value_traits + { + }; + + template <> + struct value_traits + { + 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 -- cgit v1.1