From d0fae7d13d0484977a56cbdcb85e42b9854dfba5 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 30 Jun 2011 11:57:53 +0200 Subject: Take into account precision in MySQL FLOAT type parsing --- odb/relational/mysql/context.cxx | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/odb/relational/mysql/context.cxx b/odb/relational/mysql/context.cxx index aa47b78..80a2695 100644 --- a/odb/relational/mysql/context.cxx +++ b/odb/relational/mysql/context.cxx @@ -347,6 +347,7 @@ namespace relational state s (parse_prefix); string prefix; + bool flt (false); for (sql_token t (l.next ()); s != parse_done && t.type () != sql_token::t_eos; @@ -423,7 +424,14 @@ namespace relational r.type = sql_type::BIGINT; r.unsign = true; } - else if (id == "FLOAT" || id == "FLOAT4") + else if (id == "FLOAT") + { + // Assign a type only once we know the precision of the + // float; it can be either 4 or 8 byte. + // + flt = true; + } + else if (id == "FLOAT4") { r.type = sql_type::FLOAT; } @@ -683,6 +691,13 @@ namespace relational } } + if (flt) + { + r.type = !r.range || r.range_value < 24 + ? sql_type::FLOAT + : sql_type::DOUBLE; + } + if (r.type == sql_type::invalid) { cerr << m.file () << ":" << m.line () << ":" << m.column () -- cgit v1.1