diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2011-03-25 13:09:06 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2011-03-25 13:09:06 +0200 |
commit | 534c5958af6104aea60a9fcb0d823a5c3cfed1bc (patch) | |
tree | c2488c68b31a3b72526a7db017d4997cdb93f91f /mapping/traits-mysql.hxx | |
parent | 0bea9feb8e97b0257b801f34322db72a01373468 (diff) |
SQLite support
Diffstat (limited to 'mapping/traits-mysql.hxx')
-rw-r--r-- | mapping/traits-mysql.hxx | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/mapping/traits-mysql.hxx b/mapping/traits-mysql.hxx new file mode 100644 index 0000000..497d122 --- /dev/null +++ b/mapping/traits-mysql.hxx @@ -0,0 +1,85 @@ +// file : mapping/traits-mysql.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : not copyrighted - public domain + +#ifndef TRAITS_MYSQL_HXX +#define TRAITS_MYSQL_HXX + +// +// MySQL implementation. +// + +#include <cstring> + +#include <odb/mysql/traits.hxx> + +#include "person.hxx" // date + +namespace odb +{ + namespace mysql + { + template <> + class value_traits<bool, details::buffer, id_string> + { + public: + typedef bool value_type; + typedef bool query_type; + typedef details::buffer image_type; + + static void + set_value (bool& v, + const details::buffer& b, + std::size_t n, + bool is_null) + { + v = (!is_null && n == 4 && std::strncmp ("true", b.data (), n) == 0); + } + + static void + set_image (details::buffer& b, + std::size_t& n, + bool& is_null, + bool v) + { + is_null = false; + n = v ? 4 : 5; + + if (n > b.capacity ()) + b.capacity (n); + + std::memcpy (b.data (), (v ? "true" : "false"), n); + } + }; + + template <> + class value_traits<date, MYSQL_TIME, id_date> + { + public: + typedef date value_type; + typedef date query_type; + typedef MYSQL_TIME image_type; + + static void + set_value (date& v, const MYSQL_TIME& i, bool is_null) + { + if (!is_null) + v = date (i.year, i.month, i.day); + else + v = date (0, 0, 0); + } + + static void + set_image (MYSQL_TIME& i, bool& is_null, const date& v) + { + is_null = false; + i.neg = false; + i.year = v.year (); + i.month = v.month (); + i.day = v.day (); + } + }; + } +} + +#endif // TRAITS_MYSQL_HXX |