// file : odb/mysql/exceptions.cxx // author : Boris Kolpackov // copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC // license : GNU GPL v2; see accompanying LICENSE file #include #ifdef _WIN32 # include #endif #ifdef LIBODB_MYSQL_INCLUDE_SHORT # include // CR_OUT_OF_MEMORY #else # include #endif #include // std::bad_alloc #include #include using namespace std; namespace odb { namespace mysql { database_exception:: ~database_exception () throw () { } database_exception:: database_exception (MYSQL* h) : error_ (mysql_errno (h)) { if (error_ == CR_OUT_OF_MEMORY) throw bad_alloc (); sqlstate_ = mysql_sqlstate (h); message_ = mysql_error (h); init (); } 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); 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 (); } const char* database_exception:: what () const throw () { return what_.c_str (); } } }