diff options
-rw-r--r-- | odb/mysql/exceptions.cxx | 28 | ||||
-rw-r--r-- | odb/mysql/exceptions.hxx | 1 |
2 files changed, 26 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 (); diff --git a/odb/mysql/exceptions.hxx b/odb/mysql/exceptions.hxx index a4e729b..04e787f 100644 --- a/odb/mysql/exceptions.hxx +++ b/odb/mysql/exceptions.hxx @@ -19,6 +19,7 @@ namespace odb struct database_exception: odb::database_exception { database_exception (MYSQL*); + database_exception (MYSQL_STMT*); ~database_exception () throw (); unsigned int |