From 7b8192c9e9bfa3a228938e12daa222af3bbfa6f1 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 13 Aug 2010 13:46:57 +0200 Subject: Test language-embedded queries --- common/query/traits.hxx | 58 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 common/query/traits.hxx (limited to 'common/query/traits.hxx') diff --git a/common/query/traits.hxx b/common/query/traits.hxx new file mode 100644 index 0000000..39d2ca4 --- /dev/null +++ b/common/query/traits.hxx @@ -0,0 +1,58 @@ +// file : common/query/traits.hxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2009-2010 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef TRAITS_HXX +#define TRAITS_HXX + +#include +#include + +#include + +namespace odb +{ + namespace mysql + { + template <> + class value_traits > + { + public: + typedef std::auto_ptr type; + typedef std::string value_type; + static const image_id_type image_id = id_string; + + static void + set_value (std::auto_ptr& v, + const char* s, + std::size_t n, + bool is_null) + { + v.reset (is_null ? 0 : new std::string (s, n)); + } + + static void + set_image (odb::buffer& b, + std::size_t& n, + bool& is_null, + const std::auto_ptr& v) + { + is_null = v.get () == 0; + + if (!is_null) + { + n = v->size (); + + if (n > b.capacity ()) + b.capacity (n); + + if (n != 0) + std::memcpy (b.data (), v->c_str (), n); + } + } + }; + } +} + +#endif // TRAITS_HXX -- cgit v1.1