From fd183d666dc035dadb7e73378a29975df56f1dfd Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 3 Aug 2010 14:10:31 +0200 Subject: ENUM and SET MySQL type parsing --- odb/mysql/context.cxx | 59 +++++++++++++++++++++++++++++++-------------------- 1 file changed, 36 insertions(+), 23 deletions(-) diff --git a/odb/mysql/context.cxx b/odb/mysql/context.cxx index 9f2373f..f3b9bbb 100644 --- a/odb/mysql/context.cxx +++ b/odb/mysql/context.cxx @@ -352,38 +352,51 @@ namespace mysql { t = l.next (); - if (t.type () != sql_token::t_int_lit) + // ENUM and SET have a list of members instead of the range. + // + if (r.type == sql_type::ENUM || r.type == sql_type::SET) { - cerr << m.file () << ":" << m.line () << ":" << m.column () - << " error: integer range expected in MySQL type " - << "declaration" << endl; - - throw generation_failed (); + // Skip tokens until we get the closing paren. + // + while (t.type () != sql_token::t_eos && + t.punctuation () != sql_token::p_rparen) + t = l.next (); } + else + { + if (t.type () != sql_token::t_int_lit) + { + cerr << m.file () << ":" << m.line () << ":" << m.column () + << " error: integer range expected in MySQL type " + << "declaration" << endl; - unsigned int v; - istringstream is (t.literal ()); + throw generation_failed (); + } - if (!(is >> v && is.eof ())) - { - cerr << m.file () << ":" << m.line () << ":" << m.column () - << " error: invalid range value '" << t.literal () - << "'in MySQL type declaration" << endl; + unsigned int v; + istringstream is (t.literal ()); - throw generation_failed (); - } + if (!(is >> v && is.eof ())) + { + cerr << m.file () << ":" << m.line () << ":" << m.column () + << " error: invalid range value '" << t.literal () + << "'in MySQL type declaration" << endl; - r.range = true; - r.range_value = v; + throw generation_failed (); + } - t = l.next (); + r.range = true; + r.range_value = v; - if (t.punctuation () == sql_token::p_comma) - { - // We have the second range value. Skip it. - // - l.next (); t = l.next (); + + if (t.punctuation () == sql_token::p_comma) + { + // We have the second range value. Skip it. + // + l.next (); + t = l.next (); + } } if (t.punctuation () != sql_token::p_rparen) -- cgit v1.1