Skip to content

Commit

Permalink
Fix #156 Misleading error message in exception from Statement::exec
Browse files Browse the repository at this point in the history
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
  • Loading branch information
SRombauts committed Jun 16, 2019
2 parents b38e88d + 7738989 commit 08a73ce
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/Statement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,14 @@ bool Statement::executeStep()
const int ret = tryExecuteStep();
if ((SQLITE_ROW != ret) && (SQLITE_DONE != ret)) // on row or no (more) row ready, else it's a problem
{
throw SQLite::Exception(mStmtPtr, ret);
if (ret == sqlite3_errcode(mStmtPtr))
{
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)
Expand All @@ -276,10 +283,14 @@ int Statement::exec()
{
throw SQLite::Exception("exec() does not expect results. Use executeStep.");
}
else
else if (ret == sqlite3_errcode(mStmtPtr))
{
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)
Expand Down

0 comments on commit 08a73ce

Please sign in to comment.