From 1ba1097cd1d71b945255d9401ffa4f04a036e94f Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 28 Mar 2011 11:22:59 +0200 Subject: Add SQLite-specific tests --- sqlite/types/traits.hxx | 96 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 sqlite/types/traits.hxx (limited to 'sqlite/types/traits.hxx') diff --git a/sqlite/types/traits.hxx b/sqlite/types/traits.hxx new file mode 100644 index 0000000..0f9c253 --- /dev/null +++ b/sqlite/types/traits.hxx @@ -0,0 +1,96 @@ +// file : sqlite/types/traits.hxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef TRAITS_HXX +#define TRAITS_HXX + +#include // std::memcpy, std::memset + +#include + +#include "test.hxx" // buffer + +namespace odb +{ + namespace sqlite + { + template <> + class value_traits + { + public: + typedef buffer value_type; + typedef buffer query_type; + typedef details::buffer image_type; + + static void + set_value (buffer& v, + const details::buffer& b, + std::size_t n, + bool is_null) + { + if (!is_null) + v.assign (b.data (), n); + else + v.assign (0, 0); + } + + static void + set_image (details::buffer& b, + std::size_t& n, + bool& is_null, + const buffer& v) + { + is_null = false; + n = v.size (); + + if (n > b.capacity ()) + b.capacity (n); + + if (n != 0) + std::memcpy (b.data (), v.data (), n); + } + }; + + template <> + class value_traits + { + public: + typedef string_ptr value_type; + typedef std::string query_type; + typedef details::buffer image_type; + + static void + set_value (string_ptr& v, + const details::buffer& b, + std::size_t n, + bool is_null) + { + v.reset (is_null ? 0 : new std::string (b.data (), n)); + } + + static void + set_image (details::buffer& b, + std::size_t& n, + bool& is_null, + const string_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