From bc9e3154a6ebe08c65c3be66cf642c30c5c1a726 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 22 Jul 2011 14:10:00 +0200 Subject: Parse and store MySQL ENUM enumerator strings --- odb/relational/mysql/context.cxx | 32 ++++++++++++++++++++++++++++---- odb/relational/mysql/context.hxx | 3 +++ 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/odb/relational/mysql/context.cxx b/odb/relational/mysql/context.cxx index 8fe19fe..84f2bf6 100644 --- a/odb/relational/mysql/context.cxx +++ b/odb/relational/mysql/context.cxx @@ -589,11 +589,35 @@ namespace relational // if (r.type == sql_type::ENUM || r.type == sql_type::SET) { - // Skip tokens until we get the closing paren. - // - while (t.type () != sql_token::t_eos && - t.punctuation () != sql_token::p_rparen) + while (true) + { + if (t.type () != sql_token::t_string_lit) + { + cerr << m.file () << ":" << m.line () << ":" << m.column () + << ": error: string literal expected in MySQL ENUM " + << "or SET declaration" << endl; + + throw generation_failed (); + } + + if (r.type == sql_type::ENUM) + r.enumerators.push_back (t.literal ()); + t = l.next (); + + if (t.punctuation () == sql_token::p_rparen) + break; + else if (t.punctuation () != sql_token::p_comma) + { + cerr << m.file () << ":" << m.line () << ":" << m.column () + << ": error: comma expected in MySQL ENUM or " + << "SET declaration" << endl; + + throw generation_failed (); + } + + t = l.next (); + } } else { diff --git a/odb/relational/mysql/context.hxx b/odb/relational/mysql/context.hxx index 00ebe57..26568ec 100644 --- a/odb/relational/mysql/context.hxx +++ b/odb/relational/mysql/context.hxx @@ -6,6 +6,8 @@ #ifndef ODB_RELATIONAL_MYSQL_CONTEXT_HXX #define ODB_RELATIONAL_MYSQL_CONTEXT_HXX +#include + #include namespace relational @@ -72,6 +74,7 @@ namespace relational bool unsign; bool range; unsigned int range_value; // MySQL max value is 2^32 - 1 (LONGBLOG/TEXT). + std::vector enumerators; // Enumerator strings for ENUM. }; class context: public virtual relational::context -- cgit v1.1