From 7d74507aacb63f77b763c940ef6fb6c82cb2445a Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 16 Jan 2012 09:50:11 +0200 Subject: Add SQL Server support --- mapping/traits-mssql.hxx | 86 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 mapping/traits-mssql.hxx (limited to 'mapping/traits-mssql.hxx') diff --git a/mapping/traits-mssql.hxx b/mapping/traits-mssql.hxx new file mode 100644 index 0000000..264a657 --- /dev/null +++ b/mapping/traits-mssql.hxx @@ -0,0 +1,86 @@ +// file : mapping/traits-mssql.hxx +// author : Constantin Michael +// copyright : not copyrighted - public domain + +#ifndef TRAITS_MSSQL_HXX +#define TRAITS_MSSQL_HXX + +// +// SQL Server implementation. +// + +#include // std::size_t +#include // std::strncmp, std::memcpy +#include + +#include + +#include "person.hxx" // date + +namespace odb +{ + namespace mssql + { + template <> + class value_traits + { + public: + typedef bool value_type; + typedef bool query_type; + typedef char* image_type; + + static void + set_value (bool& v, + const char* b, + std::size_t n, + bool is_null) + { + v = (!is_null && n == 4 && std::strncmp ("true", b, n) == 0); + } + + static void + set_image (char* b, + std::size_t c, + std::size_t& n, + bool& is_null, + bool v) + { + is_null = false; + n = v ? 4 : 5; + + assert (n <= c); + + std::memcpy (b, (v ? "true" : "false"), n); + } + }; + + template <> + class value_traits< ::date, id_date> + { + public: + typedef ::date value_type; + typedef ::date query_type; + typedef mssql::date image_type; + + static void + set_value (value_type& v, const image_type& i, bool is_null) + { + if (!is_null) + v = value_type (static_cast (i.year), i.month, i.day); + else + v = value_type (0, 0, 0); + } + + static void + set_image (image_type& i, bool& is_null, const value_type& v) + { + is_null = false; + i.year = static_cast (v.year ()); + i.month = static_cast (v.month ()); + i.day = static_cast (v.day ()); + } + }; + } +} + +#endif // TRAITS_MSSQL_HXX -- cgit v1.1