From 3fabd5107e81d1f75a259ba1d1fa1911c166ebac Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 18 Jul 2012 12:07:18 +0200 Subject: Convert NULLs to NaNs in SQLite for float and double This makes it consistent with SQLite behavior which converts NaNs to NULLs. --- odb/sqlite/traits.hxx | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/odb/sqlite/traits.hxx b/odb/sqlite/traits.hxx index ecd982f..65883b6 100644 --- a/odb/sqlite/traits.hxx +++ b/odb/sqlite/traits.hxx @@ -9,6 +9,7 @@ #include #include +#include // std::numeric_limits #include // std::size_t #include // std::memcpy, std::memset, std::strlen @@ -202,6 +203,45 @@ namespace odb } }; + // Float & double specialization. SQLite converts NaNs to NULLs so + // we convert NULLs to NaNs for consistency. + // + template + struct real_value_traits + { + typedef T value_type; + typedef T query_type; + typedef double image_type; + + static void + set_value (T& v, double i, bool is_null) + { + if (!is_null) + v = T (i); + else + v = std::numeric_limits::quiet_NaN (); + } + + static void + set_image (double& i, bool& is_null, T v) + { + is_null = false; + i = image_type (v); + } + }; + + template <> + struct LIBODB_SQLITE_EXPORT default_value_traits: + real_value_traits + { + }; + + template <> + struct LIBODB_SQLITE_EXPORT default_value_traits: + real_value_traits + { + }; + // std::string specialization. // template <> -- cgit v1.1