Skip to content

Commit

Permalink
Fix #73 Wrong exception thrown by Database constructor
Browse files Browse the repository at this point in the history
 - switched from sqlite3_errmsg() to sqlite3_errstr() where applicable
  • Loading branch information
SRombauts committed Nov 10, 2015
1 parent 24153e5 commit b7b440d
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 13 deletions.
2 changes: 1 addition & 1 deletion include/SQLiteCpp/Database.h
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ class Database
{
if (SQLITE_OK != aRet)
{
throw SQLite::Exception(sqlite3_errmsg(mpSQLite));
throw SQLite::Exception(sqlite3_errstr(aRet));
}
}

Expand Down
2 changes: 1 addition & 1 deletion include/SQLiteCpp/Statement.h
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ class Statement
{
if (SQLITE_OK != aRet)
{
throw SQLite::Exception(sqlite3_errmsg(mStmtPtr));
throw SQLite::Exception(sqlite3_errstr(aRet));
}
}

Expand Down
6 changes: 1 addition & 5 deletions src/Backup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,7 @@ int Backup::executeStep(const int aNumPage /* = -1 */)
if (SQLITE_OK != res && SQLITE_DONE != res &&
SQLITE_BUSY != res && SQLITE_LOCKED != res)
{
std::string strerr("Backup executeStep error");
#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
std::string strerr = sqlite3_errstr(res);
throw SQLite::Exception(strerr);
}
return res;
Expand Down
6 changes: 3 additions & 3 deletions src/Database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Database::Database(const char* apFilename,
const int ret = sqlite3_open_v2(apFilename, &mpSQLite, aFlags, apVfs);
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
throw SQLite::Exception(strerr);
}
Expand All @@ -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());
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
throw SQLite::Exception(strerr);
}
Expand All @@ -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.
*
* 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:
* 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;".
Expand Down
6 changes: 3 additions & 3 deletions src/Statement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ bool Statement::executeStep()
{
mbOk = false;
mbDone = false;
throw SQLite::Exception(sqlite3_errmsg(mStmtPtr));
throw SQLite::Exception(sqlite3_errstr(ret));
}
}
else
Expand Down Expand Up @@ -227,7 +227,7 @@ int Statement::exec()
{
mbOk = false;
mbDone = false;
throw SQLite::Exception(sqlite3_errmsg(mStmtPtr));
throw SQLite::Exception(sqlite3_errstr(ret));
}
}
else
Expand Down Expand Up @@ -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);
if (SQLITE_OK != ret)
{
throw SQLite::Exception(sqlite3_errmsg(mpSQLite));
throw SQLite::Exception(sqlite3_errstr(ret));
}
// Initialize the reference counter of the sqlite3_stmt :
// used to share the mStmtPtr between Statement and Column objects;
Expand Down

0 comments on commit b7b440d

Please sign in to comment.