From 904c0628b231cb19a065df8e15b09c25676beeb9 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 26 Jul 2010 15:42:20 +0200 Subject: Add MYSQL_STMT c-tor, filter out of memory condition --- odb/mysql/exceptions.cxx | 28 +++++++++++++++++++++++++--- 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 // CR_OUT_OF_MEMORY + +#include // std::bad_alloc #include #include @@ -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 -- cgit v1.1