From 88d506ea0debc62dbcca100d020570fd470a51ec Mon Sep 17 00:00:00 2001 From: Constantin Michael Date: Thu, 9 Jun 2011 09:30:38 +0200 Subject: Add PostgreSQL FLOAT and timezone suffix parsing --- odb/relational/pgsql/context.cxx | 59 +++++++++++++++++++++++++++++++++++++++- odb/relational/pgsql/context.hxx | 5 ---- 2 files changed, 58 insertions(+), 6 deletions(-) (limited to 'odb/relational/pgsql') diff --git a/odb/relational/pgsql/context.cxx b/odb/relational/pgsql/context.cxx index f57682a..fb25936 100644 --- a/odb/relational/pgsql/context.cxx +++ b/odb/relational/pgsql/context.cxx @@ -339,11 +339,13 @@ namespace relational parse_prefix, parse_name, parse_range, + parse_suffix, parse_done }; state s (parse_prefix); string prefix; + bool flt (false); for (sql_token t (l.next ()); s != parse_done && t.type () != sql_token::t_eos; @@ -412,7 +414,10 @@ namespace relational } else if (id == "FLOAT") { - r.type = sql_type::DOUBLE; + // Assign a type only once we know the precision of the + // float. + // + flt_ = true; } else if (id == "DECIMAL" || id == "NUMERIC") { @@ -569,6 +574,51 @@ namespace relational throw generation_failed (); } + + s = parse_suffix; + continue; + } + + // Fall through. + // + s = parse_suffix; + } + case parse_suffix: + { + if (r.type == sql_type::TIME || r.type == sql_type::TIMESTAMP) + { + string const& id1 (context::upcase (t.identifier ())); + + if (id1 == "WITH") + { + t = l.next (); + tt = t.type (); + + if (tt == sql_token::t_identifier) + { + string const& id2 (context::upcase (t.identifier ())); + + if (id2 == "TIME") + { + t = l.next (); + tt = t.type (); + + if (tt == sql_token::t_identifier) + { + string const& id3 (context::upcase (t.identifier ())); + + if (id3 == "ZONE") + { + cerr << m.file () << ":" << m.line () << ":" + << m.column ()<< ": error: PostgreSQL time " + << "zones are not currently supported" << endl; + + throw generation_failed (); + } + } + } + } + } } s = parse_done; @@ -597,6 +647,13 @@ namespace relational } } + if (flt) + { + r.type = r.range && r.range_value < 25 ? + sql_type::REAL : + sql_type::DOUBLE; + } + if (r.type == sql_type::invalid) { cerr << m.file () << ":" << m.line () << ":" << m.column () diff --git a/odb/relational/pgsql/context.hxx b/odb/relational/pgsql/context.hxx index 468f73a..f570c86 100644 --- a/odb/relational/pgsql/context.hxx +++ b/odb/relational/pgsql/context.hxx @@ -27,7 +27,6 @@ namespace relational // Float types. // - FLOAT, REAL, DOUBLE, DECIMAL, @@ -86,10 +85,6 @@ namespace relational // protected: // virtual string - // quote_id_impl (string const&) const; - - // protected: - // virtual string // database_type_impl (semantics::type&, // semantics::names*, // semantics::context&, -- cgit v1.1