From 4acabe57939ff37bad0a8aabc5164b6d5add449b Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 18 Feb 2011 17:56:53 +0200 Subject: Factor out MySQL error to exception translation into separate function --- odb/mysql/connection.cxx | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'odb/mysql/connection.cxx') diff --git a/odb/mysql/connection.cxx b/odb/mysql/connection.cxx index e77c04d..1395592 100644 --- a/odb/mysql/connection.cxx +++ b/odb/mysql/connection.cxx @@ -4,6 +4,7 @@ // license : GNU GPL v2; see accompanying LICENSE file #include // std::bad_alloc +#include #include #include @@ -40,9 +41,18 @@ namespace odb db.socket (), db.client_flags () | CLIENT_FOUND_ROWS) == 0) { - database_exception e (handle_); + // We cannot use translate_error() here since there is no connection + // yet. + // + unsigned int e (mysql_errno (handle_)); + string sqlstate (mysql_sqlstate (handle_)); + string message (mysql_error (handle_)); mysql_close (handle_); - throw e; + + if (e == CR_OUT_OF_MEMORY) + throw bad_alloc (); + + throw database_exception (e, sqlstate, message); } } -- cgit v1.1