Skip to content

Commit 08a73ce

Browse files
committed
Fix SRombauts#156 Misleading error message in exception from Statement::exec
Fix SRombauts#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
2 parents b38e88d + 7738989 commit 08a73ce

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/Statement.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,14 @@ bool Statement::executeStep()
260260
const int ret = tryExecuteStep();
261261
if ((SQLITE_ROW != ret) && (SQLITE_DONE != ret)) // on row or no (more) row ready, else it's a problem
262262
{
263-
throw SQLite::Exception(mStmtPtr, ret);
263+
if (ret == sqlite3_errcode(mStmtPtr))
264+
{
265+
throw SQLite::Exception(mStmtPtr, ret);
266+
}
267+
else
268+
{
269+
throw SQLite::Exception("Statement needs to be reseted", ret);
270+
}
264271
}
265272

266273
return mbHasRow; // true only if one row is accessible by getColumn(N)
@@ -276,10 +283,14 @@ int Statement::exec()
276283
{
277284
throw SQLite::Exception("exec() does not expect results. Use executeStep.");
278285
}
279-
else
286+
else if (ret == sqlite3_errcode(mStmtPtr))
280287
{
281288
throw SQLite::Exception(mStmtPtr, ret);
282289
}
290+
else
291+
{
292+
throw SQLite::Exception("Statement needs to be reseted", ret);
293+
}
283294
}
284295

285296
// Return the number of rows modified by those SQL statements (INSERT, UPDATE or DELETE)

0 commit comments

Comments
 (0)