From 35e514ddf8c5b1ca72ecfa841b05d3f047650132 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 18 Aug 2010 17:55:55 +0200 Subject: Add another constructor version --- odb/mysql/exceptions.cxx | 23 ++++++++++++++++++++--- odb/mysql/exceptions.hxx | 8 ++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/odb/mysql/exceptions.cxx b/odb/mysql/exceptions.cxx index 71c61ec..1373874 100644 --- a/odb/mysql/exceptions.cxx +++ b/odb/mysql/exceptions.cxx @@ -31,9 +31,7 @@ namespace odb sqlstate_ = mysql_sqlstate (h); message_ = mysql_error (h); - ostringstream ostr; - ostr << error_ << " (" << sqlstate_ << "): " << message_; - what_ = ostr.str (); + init (); } database_exception:: @@ -46,6 +44,25 @@ namespace odb sqlstate_ = mysql_stmt_sqlstate (h); message_ = mysql_stmt_error (h); + init (); + } + + database_exception:: + database_exception (unsigned int e, const string& s, const string& m) + : error_ (e) + { + if (error_ == CR_OUT_OF_MEMORY) + throw bad_alloc (); + + sqlstate_ = s; + message_ = m; + + init (); + } + + void database_exception:: + init () + { ostringstream ostr; ostr << error_ << " (" << sqlstate_ << "): " << message_; what_ = ostr.str (); diff --git a/odb/mysql/exceptions.hxx b/odb/mysql/exceptions.hxx index ad9efa3..86cbb19 100644 --- a/odb/mysql/exceptions.hxx +++ b/odb/mysql/exceptions.hxx @@ -22,6 +22,10 @@ namespace odb { database_exception (MYSQL*); database_exception (MYSQL_STMT*); + database_exception (unsigned int, + const std::string& sqlstate, + const std::string& message); + ~database_exception () throw (); unsigned int @@ -46,6 +50,10 @@ namespace odb what () const throw (); private: + void + init (); + + private: unsigned int error_; std::string sqlstate_; std::string message_; -- cgit v1.1