diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2010-07-26 15:42:20 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2010-07-26 15:42:20 +0200 |
commit | 904c0628b231cb19a065df8e15b09c25676beeb9 (patch) | |
tree | 4a50b8071585da298abc016aca86d54e7db3e2f8 | |
parent | 7de4ae99d764d3a5666dea36ae1e4b226be88595 (diff) |
Add MYSQL_STMT c-tor, filter out of memory condition
-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 |