Surface SQLITE_MISUSE errors so invalid JSON paths are reported to the user (fixes #4113)#4121
Surface SQLITE_MISUSE errors so invalid JSON paths are reported to the user (fixes #4113)#4121DORI2001 wants to merge 1 commit intosqlitebrowser:masterfrom
Conversation
|
Are you sure there isn't a simpler way to detect this error? The Unless In fact, I've seen we are receiving SQLITE_MISUSE, you can see it in the error log (SQL Log dock). We are ignoring it, I don't know why (the history should be reviewed): Line 249 in 2b39cef sqlitebrowser/src/sqlitedb.cpp Line 1218 in 2b39cef I just tried to remove the first instance and leave it through the default branch, but the application hangs, so it is not so simple. We should investigate this further to fix it in the correct way, and not only for these JSON cases. |
|
Thanks for the detailed review, this was very helpful. I reworked the PR to remove the regex-based JSON pre-validation approach and switched to a general execution-status handling path instead. What I changed: SQLITE_MISUSE is no longer ignored in RunSql. |
59a008d to
6445be4
Compare
|
Thanks again for the detailed review @mgrojo — you were right. I've reworked the PR completely. The regex/ The previous comment I left claiming the PR had already been reworked was inaccurate — apologies for the confusion. The code is correct now. |
|
In the files change tab, I still see the original regexp implementation. Can you check? |
Previously, SQLITE_MISUSE was silently ignored (empty break), so errors
like invalid JSON path syntax ('$[-1]') were never shown to the user.
Now the error message from sqlite3_errmsg() is surfaced the same way as
any other execution error, matching the behaviour of the sqlite3 CLI.
Fixes sqlitebrowser#4113
6445be4 to
bcf4364
Compare
|
You were right, sorry for the confusion. The previous force-push didn't actually land on GitHub — the branch on GitHub still had the old regex implementation. I've now squashed the entire history into a single clean commit. The PR diff is now exactly the 1-line change we discussed: adding |
|
Hi @mgrojo — just wanted to confirm the branch is now clean. The current diff is exactly the 1-line change we discussed: adding |
|
That doesn't seem enough, as I commented in #4121 (comment), this can hang sqlitebrowser, for example, with this: select json_extract('[3]', '$[-1]');
(you have to include the empty blank lines) That can be solved with this patch: diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp
index 02335ca9..1ded3f97 100644
--- a/src/MainWindow.cpp
+++ b/src/MainWindow.cpp
@@ -1245,7 +1245,8 @@ void MainWindow::executeQuery()
if (char_at_index == '\r' || char_at_index == '\n') {
execute_from_line++;
// The next lines could be empty, so skip all of them too.
- while(editor->text(execute_from_line).trimmed().isEmpty())
+ while(execute_from_line <= editor->lines() &&
+ editor->text(execute_from_line).trimmed().isEmpty())
execute_from_line++;
execute_from_index = 0;
}But the question is, if you delete the blank lines, like this (be sure to have just one line), you still get an OK response. We're back to square one. select json_extract('[3]', '$[-1]'); |
Problem
When
json_extract('[3]', '$[-1]')is executed, SQLite internally returnsSQLITE_MISUSEbecause$[-1]is not valid SQLite JSON path syntax. However, sqlitebrowser was silently swallowingSQLITE_MISUSEinRunSql.cpp, so the user saw a success message and 0 rows instead of an error.Root Cause
In
RunSql.cpp, the switch onsql3statushad an explicitcase SQLITE_MISUSE: break;which discarded the error without setting theerrorstring. All other non-success statuses fell through to thedefault:branch which callssqlite3_errmsg()and surfaces the message to the user.Fix
Remove the
case SQLITE_MISUSE: break;so thatSQLITE_MISUSEfalls through todefault:like every other error code. SQLite then surfaces its native message:This is a 2-line change in
src/RunSql.cpp.Testing
The existing CI suite covers this. No regression tests were added because the fix relies on SQLite's own error reporting — a unit test would require a real SQLite execution context.
Closes #4113.