From 6b8def06796d1e4fc9e6e7e75ce59bccf6899261 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 10 Jul 2012 15:17:16 +0200 Subject: Add support for custom database type mapping New pragma qualifier, map, and specifiers: as, to, from. New tests: /custom. --- oracle/custom/traits.hxx | 77 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 oracle/custom/traits.hxx (limited to 'oracle/custom/traits.hxx') diff --git a/oracle/custom/traits.hxx b/oracle/custom/traits.hxx new file mode 100644 index 0000000..8f3e81e --- /dev/null +++ b/oracle/custom/traits.hxx @@ -0,0 +1,77 @@ +// file : oracle/types/traits.hxx +// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef TRAITS_HXX +#define TRAITS_HXX + +#include +#include +#include // std::memcpy +#include // std::memcpy + +#include + +namespace odb +{ + namespace oracle + { + + template <> + class value_traits, id_string> + { + public: + typedef std::vector value_type; + typedef value_type query_type; + typedef details::buffer image_type; + + static void + set_value (value_type& v, + const char* b, + std::size_t n, + bool is_null) + { + v.clear (); + + if (!is_null) + { + // Array format is "n1,n2,n3...". + // + std::istringstream is (std::string (b, n)); + + for (char c; !is.eof (); is >> c) + { + v.push_back (int ()); + is >> v.back (); + } + } + } + + static void + set_image (char* b, + std::size_t c, + std::size_t& n, + bool& is_null, + const value_type& v) + { + is_null = false; + std::ostringstream os; + + for (value_type::const_iterator i (v.begin ()), e (v.end ()); i != e;) + { + os << *i; + + if (++i != e) + os << ','; + } + + const std::string& s (os.str ()); + n = s.size (); + assert (n <= c); + std::memcpy (b, s.c_str (), n); + } + }; + } +} + +#endif // TRAITS_HXX -- cgit v1.1