00001 #include "SqliteException.h" 00002 #include "InvalidUseException.h" 00003 #include <sstream> 00004 00005 namespace sqlite 00006 { 00007 00008 SqliteException::SqliteException(sqlite3* db): 00009 msg(sqlite3_errmsg(db)), 00010 code(sqlite3_errcode(db)) 00011 { 00012 } 00013 00014 SqliteException::SqliteException(int code, std::string const& msg): 00015 msg(msg), 00016 code(code) 00017 { 00018 } 00019 00020 SqliteException::SqliteException(int code, sqlite3* db): 00021 msg(sqlite3_errmsg(db)), 00022 code(code) 00023 { 00024 } 00025 00026 SqliteException::~SqliteException() throw() 00027 { 00028 } 00029 00030 const char* SqliteException::what() const throw() 00031 { 00032 std::ostringstream sstream; 00033 sstream << "Sqlite error, code: " << code << ", message: " << msg; 00034 return sstream.str().c_str(); 00035 } 00036 00037 void throw_sqlite_status(int code, sqlite3* db) 00038 { 00039 if (code == SQLITE_OK) 00040 return; 00041 if (code == SQLITE_MISUSE) 00042 throw InvalidUseException("SQLite reports MISUSE"); 00043 throw SqliteException(code, db); 00044 } 00045 00046 }