aboutsummaryrefslogtreecommitdiff
path: root/odb/mysql/connection.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2011-02-18 17:56:53 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2011-02-18 17:56:53 +0200
commit4acabe57939ff37bad0a8aabc5164b6d5add449b (patch)
tree1211cf34b447014671effc59770f06f1cc0e3bb8 /odb/mysql/connection.cxx
parenta534bbdabe677b67687c9d0093cba4a800b6b766 (diff)
Factor out MySQL error to exception translation into separate function
Diffstat (limited to 'odb/mysql/connection.cxx')
-rw-r--r--odb/mysql/connection.cxx14
1 files changed, 12 insertions, 2 deletions
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 <new> // std::bad_alloc
+#include <string>
#include <odb/mysql/database.hxx>
#include <odb/mysql/connection.hxx>
@@ -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);
}
}