Fix #73 Wrong exception thrown by Database constructor

- switched from sqlite3_errmsg() to sqlite3_errstr() where applicable
This commit is contained in:
Sébastien Rombauts 2015-11-10 18:32:24 +01:00
parent 24153e5293
commit b7b440de5d
5 changed files with 9 additions and 13 deletions

View File

@ -378,7 +378,7 @@ private:
{ {
if (SQLITE_OK != aRet) if (SQLITE_OK != aRet)
{ {
throw SQLite::Exception(sqlite3_errmsg(mpSQLite)); throw SQLite::Exception(sqlite3_errstr(aRet));
} }
} }

View File

@ -457,7 +457,7 @@ private:
{ {
if (SQLITE_OK != aRet) if (SQLITE_OK != aRet)
{ {
throw SQLite::Exception(sqlite3_errmsg(mStmtPtr)); throw SQLite::Exception(sqlite3_errstr(aRet));
} }
} }

View File

@ -85,11 +85,7 @@ int Backup::executeStep(const int aNumPage /* = -1 */)
if (SQLITE_OK != res && SQLITE_DONE != res && if (SQLITE_OK != res && SQLITE_DONE != res &&
SQLITE_BUSY != res && SQLITE_LOCKED != res) SQLITE_BUSY != res && SQLITE_LOCKED != res)
{ {
std::string strerr("Backup executeStep error"); std::string strerr = sqlite3_errstr(res);
#if SQLITE_VERSION_NUMBER >= 3007015 // SQLite v3.7.15 is the first version with sqlite3_errstr() interface
strerr += "with error message ";
strerr += sqlite3_errstr(res);
#endif
throw SQLite::Exception(strerr); throw SQLite::Exception(strerr);
} }
return res; return res;

View File

@ -36,7 +36,7 @@ Database::Database(const char* apFilename,
const int ret = sqlite3_open_v2(apFilename, &mpSQLite, aFlags, apVfs); const int ret = sqlite3_open_v2(apFilename, &mpSQLite, aFlags, apVfs);
if (SQLITE_OK != ret) if (SQLITE_OK != ret)
{ {
std::string strerr = sqlite3_errmsg(mpSQLite); std::string strerr = sqlite3_errstr(ret);
sqlite3_close(mpSQLite); // close is required even in case of error on opening sqlite3_close(mpSQLite); // close is required even in case of error on opening
throw SQLite::Exception(strerr); throw SQLite::Exception(strerr);
} }
@ -58,7 +58,7 @@ Database::Database(const std::string& aFilename,
const int ret = sqlite3_open_v2(aFilename.c_str(), &mpSQLite, aFlags, aVfs.empty() ? NULL : aVfs.c_str()); const int ret = sqlite3_open_v2(aFilename.c_str(), &mpSQLite, aFlags, aVfs.empty() ? NULL : aVfs.c_str());
if (SQLITE_OK != ret) if (SQLITE_OK != ret)
{ {
std::string strerr = sqlite3_errmsg(mpSQLite); std::string strerr = sqlite3_errstr(ret);
sqlite3_close(mpSQLite); // close is required even in case of error on opening sqlite3_close(mpSQLite); // close is required even in case of error on opening
throw SQLite::Exception(strerr); throw SQLite::Exception(strerr);
} }
@ -85,7 +85,7 @@ Database::~Database() noexcept // nothrow
/** /**
* @brief Set a busy handler that sleeps for a specified amount of time when a table is locked. * @brief Set a busy handler that sleeps for a specified amount of time when a table is locked.
* *
* This is usefull in multithreaded program to handle case where a table is locked for writting by a thread. * This is useful in multithreaded program to handle case where a table is locked for writting by a thread.
* Any other thread cannot access the table and will receive a SQLITE_BUSY error: * Any other thread cannot access the table and will receive a SQLITE_BUSY error:
* setting a timeout will wait and retry up to the time specified before returning this SQLITE_BUSY error. * setting a timeout will wait and retry up to the time specified before returning this SQLITE_BUSY error.
* Reading the value of timeout for current connection can be done with SQL query "PRAGMA busy_timeout;". * Reading the value of timeout for current connection can be done with SQL query "PRAGMA busy_timeout;".

View File

@ -195,7 +195,7 @@ bool Statement::executeStep()
{ {
mbOk = false; mbOk = false;
mbDone = false; mbDone = false;
throw SQLite::Exception(sqlite3_errmsg(mStmtPtr)); throw SQLite::Exception(sqlite3_errstr(ret));
} }
} }
else else
@ -227,7 +227,7 @@ int Statement::exec()
{ {
mbOk = false; mbOk = false;
mbDone = false; mbDone = false;
throw SQLite::Exception(sqlite3_errmsg(mStmtPtr)); throw SQLite::Exception(sqlite3_errstr(ret));
} }
} }
else else
@ -317,7 +317,7 @@ Statement::Ptr::Ptr(sqlite3* apSQLite, std::string& aQuery) :
const int ret = sqlite3_prepare_v2(apSQLite, aQuery.c_str(), static_cast<int>(aQuery.size()), &mpStmt, NULL); const int ret = sqlite3_prepare_v2(apSQLite, aQuery.c_str(), static_cast<int>(aQuery.size()), &mpStmt, NULL);
if (SQLITE_OK != ret) if (SQLITE_OK != ret)
{ {
throw SQLite::Exception(sqlite3_errmsg(mpSQLite)); throw SQLite::Exception(sqlite3_errstr(ret));
} }
// Initialize the reference counter of the sqlite3_stmt : // Initialize the reference counter of the sqlite3_stmt :
// used to share the mStmtPtr between Statement and Column objects; // used to share the mStmtPtr between Statement and Column objects;