aboutsummaryrefslogtreecommitdiff
path: root/odb/mysql/exceptions.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'odb/mysql/exceptions.cxx')
-rw-r--r--odb/mysql/exceptions.cxx28
1 files changed, 25 insertions, 3 deletions
diff --git a/odb/mysql/exceptions.cxx b/odb/mysql/exceptions.cxx
index 4ee80fb..395961e 100644
--- a/odb/mysql/exceptions.cxx
+++ b/odb/mysql/exceptions.cxx
@@ -3,6 +3,9 @@
// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC
// license : GNU GPL v2; see accompanying LICENSE file
+#include <mysql/errmsg.h> // CR_OUT_OF_MEMORY
+
+#include <new> // std::bad_alloc
#include <sstream>
#include <odb/mysql/exceptions.hxx>
@@ -20,10 +23,29 @@ namespace odb
database_exception::
database_exception (MYSQL* h)
- : error_ (mysql_errno (h)),
- sqlstate_ (mysql_sqlstate (h)),
- message_ (mysql_error (h))
+ : error_ (mysql_errno (h))
+ {
+ if (error_ == CR_OUT_OF_MEMORY)
+ throw bad_alloc ();
+
+ sqlstate_ = mysql_sqlstate (h);
+ message_ = mysql_error (h);
+
+ ostringstream ostr;
+ ostr << error_ << " (" << sqlstate_ << "): " << message_;
+ what_ = ostr.str ();
+ }
+
+ database_exception::
+ database_exception (MYSQL_STMT* h)
+ : error_ (mysql_stmt_errno (h))
{
+ if (error_ == CR_OUT_OF_MEMORY)
+ throw bad_alloc ();
+
+ sqlstate_ = mysql_stmt_sqlstate (h);
+ message_ = mysql_stmt_error (h);
+
ostringstream ostr;
ostr << error_ << " (" << sqlstate_ << "): " << message_;
what_ = ostr.str ();