aboutsummaryrefslogtreecommitdiff
path: root/odb/mysql/exceptions.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2010-07-26 15:42:20 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2010-07-26 15:42:20 +0200
commit904c0628b231cb19a065df8e15b09c25676beeb9 (patch)
tree4a50b8071585da298abc016aca86d54e7db3e2f8 /odb/mysql/exceptions.cxx
parent7de4ae99d764d3a5666dea36ae1e4b226be88595 (diff)
Add MYSQL_STMT c-tor, filter out of memory condition
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 ();