Fix #156 Misleading error message in exception from Statement::exec

Fix #199

the problem is that tryExecuteStep returns SQLITE_MISUSE when it was not used properly. Since this is set manually this is not the error state of the statement, so when checking the error message of the statement there obviously is none, since there was no error.
fixes this problem by checking whether the error code is the same as the error state of the statement
This commit is contained in:
Sébastien Rombauts 2019-06-16 15:19:25 +02:00
commit 08a73ce90b

View File

@ -259,9 +259,16 @@ bool Statement::executeStep()
{ {
const int ret = tryExecuteStep(); const int ret = tryExecuteStep();
if ((SQLITE_ROW != ret) && (SQLITE_DONE != ret)) // on row or no (more) row ready, else it's a problem if ((SQLITE_ROW != ret) && (SQLITE_DONE != ret)) // on row or no (more) row ready, else it's a problem
{
if (ret == sqlite3_errcode(mStmtPtr))
{ {
throw SQLite::Exception(mStmtPtr, ret); throw SQLite::Exception(mStmtPtr, ret);
} }
else
{
throw SQLite::Exception("Statement needs to be reseted", ret);
}
}
return mbHasRow; // true only if one row is accessible by getColumn(N) return mbHasRow; // true only if one row is accessible by getColumn(N)
} }
@ -276,10 +283,14 @@ int Statement::exec()
{ {
throw SQLite::Exception("exec() does not expect results. Use executeStep."); throw SQLite::Exception("exec() does not expect results. Use executeStep.");
} }
else else if (ret == sqlite3_errcode(mStmtPtr))
{ {
throw SQLite::Exception(mStmtPtr, ret); throw SQLite::Exception(mStmtPtr, ret);
} }
else
{
throw SQLite::Exception("Statement needs to be reseted", ret);
}
} }
// Return the number of rows modified by those SQL statements (INSERT, UPDATE or DELETE) // Return the number of rows modified by those SQL statements (INSERT, UPDATE or DELETE)