aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2012-07-18 12:07:18 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2012-07-18 12:07:18 +0200
commit3fabd5107e81d1f75a259ba1d1fa1911c166ebac (patch)
tree0bf81937fa52a9606b6336b60606269dbe6908b8
parent6c54f21ce97f52d7df7df3f980586bb70a295d97 (diff)
Convert NULLs to NaNs in SQLite for float and double
This makes it consistent with SQLite behavior which converts NaNs to NULLs.
-rw-r--r--odb/sqlite/traits.hxx40
1 files changed, 40 insertions, 0 deletions
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 <string>
#include <vector>
+#include <limits> // std::numeric_limits
#include <cstddef> // std::size_t
#include <cstring> // 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 <typename T>
+ 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<T>::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<float, id_real>:
+ real_value_traits<float>
+ {
+ };
+
+ template <>
+ struct LIBODB_SQLITE_EXPORT default_value_traits<double, id_real>:
+ real_value_traits<double>
+ {
+ };
+
// std::string specialization.
//
template <>