summaryrefslogtreecommitdiff
path: root/odb/relational/mysql/context.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'odb/relational/mysql/context.cxx')
-rw-r--r--odb/relational/mysql/context.cxx96
1 files changed, 43 insertions, 53 deletions
diff --git a/odb/relational/mysql/context.cxx b/odb/relational/mysql/context.cxx
index 08f2df5..8862edf 100644
--- a/odb/relational/mysql/context.cxx
+++ b/odb/relational/mysql/context.cxx
@@ -67,16 +67,19 @@ namespace relational
}
context::
- context (ostream& os, semantics::unit& u, options_type const& ops)
+ context (ostream& os,
+ semantics::unit& u,
+ options_type const& ops,
+ sema_rel::model* m)
: root_context (os, u, ops, data_ptr (new (shared) data (os))),
- base_context (static_cast<data*> (root_context::data_.get ())),
+ base_context (static_cast<data*> (root_context::data_.get ()), m),
data_ (static_cast<data*> (base_context::data_))
{
assert (current_ == 0);
current_ = this;
- data_->generate_grow_ = true;
- data_->need_alias_as_ = true;
+ generate_grow = true;
+ need_alias_as = true;
data_->bind_vector_ = "MYSQL_BIND*";
data_->truncated_vector_ = "my_bool*";
@@ -299,9 +302,6 @@ namespace relational
// SQL type parsing.
//
- static sql_type
- parse_sql_type (semantics::data_member& m, std::string const& sql);
-
sql_type const& context::
column_sql_type (semantics::data_member& m, string const& kp)
{
@@ -310,18 +310,30 @@ namespace relational
: "mysql-" + kp + "-column-sql-type");
if (!m.count (key))
- m.set (key, parse_sql_type (m, column_type (m, kp)));
+ {
+ try
+ {
+ m.set (key, parse_sql_type (column_type (m, kp)));
+ }
+ catch (invalid_sql_type const& e)
+ {
+ cerr << m.file () << ":" << m.line () << ":" << m.column ()
+ << ": error: " << e.message () << endl;
+
+ throw operation_failed ();
+ }
+ }
return m.get<sql_type> (key);
}
- static sql_type
- parse_sql_type (semantics::data_member& m, string const& sql)
+ sql_type context::
+ parse_sql_type (string const& sqlt)
{
try
{
sql_type r;
- sql_lexer l (sql);
+ sql_lexer l (sqlt);
// While most type names use single identifier, there are
// a couple of exceptions to this rule:
@@ -568,16 +580,13 @@ namespace relational
if (r.type == sql_type::invalid)
{
- cerr << m.file () << ":" << m.line () << ":" <<
- m.column () << ":";
-
if (tt == sql_token::t_identifier)
- cerr << " error: unknown MySQL type '" <<
- t.identifier () << "'" << endl;
+ {
+ throw invalid_sql_type (
+ "unknown MySQL type '" + t.identifier () + "'");
+ }
else
- cerr << " error: expected MySQL type name" << endl;
-
- throw operation_failed ();
+ throw invalid_sql_type ("expected MySQL type name");
}
// Fall through.
@@ -598,11 +607,9 @@ namespace relational
{
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 operation_failed ();
+ throw invalid_sql_type (
+ "string literal expected in MySQL ENUM or SET "
+ "declaration");
}
if (r.type == sql_type::ENUM)
@@ -614,11 +621,8 @@ namespace relational
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 operation_failed ();
+ throw invalid_sql_type (
+ "comma expected in MySQL ENUM or SET declaration");
}
t = l.next ();
@@ -628,11 +632,8 @@ namespace relational
{
if (t.type () != sql_token::t_int_lit)
{
- cerr << m.file () << ":" << m.line () << ":" << m.column ()
- << ": error: integer range expected in MySQL type "
- << "declaration" << endl;
-
- throw operation_failed ();
+ throw invalid_sql_type (
+ "integer range expected in MySQL type declaration");
}
unsigned int v;
@@ -640,11 +641,9 @@ namespace relational
if (!(is >> v && is.eof ()))
{
- cerr << m.file () << ":" << m.line () << ":" << m.column ()
- << ": error: invalid range value '" << t.literal ()
- << "'in MySQL type declaration" << endl;
-
- throw operation_failed ();
+ throw invalid_sql_type (
+ "invalid range value '" + t.literal () + "' in MySQL "
+ "type declaration");
}
r.range = true;
@@ -671,11 +670,8 @@ namespace relational
if (t.punctuation () != sql_token::p_rparen)
{
- cerr << m.file () << ":" << m.line () << ":" << m.column ()
- << ": error: expected ')' in MySQL type declaration"
- << endl;
-
- throw operation_failed ();
+ throw invalid_sql_type (
+ "expected ')' in MySQL type declaration");
}
s = parse_sign;
@@ -729,10 +725,7 @@ namespace relational
if (r.type == sql_type::invalid)
{
- cerr << m.file () << ":" << m.line () << ":" << m.column ()
- << ": error: incomplete MySQL type declaration" << endl;
-
- throw operation_failed ();
+ throw invalid_sql_type ("incomplete MySQL type declaration");
}
// If range is omitted for CHAR or BIT types, it defaults to 1.
@@ -747,11 +740,8 @@ namespace relational
}
catch (sql_lexer::invalid_input const& e)
{
- cerr << m.file () << ":" << m.line () << ":" << m.column ()
- << ": error: invalid MySQL type declaration: " << e.message
- << endl;
-
- throw operation_failed ();
+ throw invalid_sql_type (
+ "invalid MySQL type declaration: " + e.message);
}
}
}