diff options
Diffstat (limited to 'odb/mysql/traits.cxx')
-rw-r--r-- | odb/mysql/traits.cxx | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/odb/mysql/traits.cxx b/odb/mysql/traits.cxx new file mode 100644 index 0000000..f90cc0b --- /dev/null +++ b/odb/mysql/traits.cxx @@ -0,0 +1,90 @@ +// file : odb/mysql/traits.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +#include <cstring> // std::memcpy, std::strlen + +#include <odb/mysql/traits.hxx> + +using namespace std; + +namespace odb +{ + namespace mysql + { + // + // value_traits<string> + // + + void value_traits<string>:: + set_image (char* s, + size_t c, + size_t& n, + bool& is_null, + const string& v) + { + is_null = false; + n = v.size (); + + if (n > c) + n = c; + + if (n != 0) + memcpy (s, v.c_str (), n); + } + + void value_traits<string>:: + set_image (details::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); + } + + // + // value_traits<const char*> + // + + void value_traits<const char*>:: + set_image (char* s, + size_t c, + size_t& n, + bool& is_null, + const char* v) + { + is_null = false; + n = strlen (v); + + if (n > c) + n = c; + + if (n != 0) + memcpy (s, v, n); + } + + void value_traits<const char*>:: + set_image (details::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); + } + } +} |