fix(sqlite): don't execute a second smuggled-in statement during column inference - #1012
Merged
ZhuchkaTriplesix merged 1 commit intoSep 27, 2026
Merged
Conversation
…mn inference (Closes #1005) SqliteConnection.inferQueryColumns probes zero-row queries by wrapping the user's SQL in `CREATE TEMP VIEW ... AS <sql>` via Database.execute, which (unlike rawQuery) runs every statement it's given. A query like `SELECT * FROM t WHERE 0; DELETE FROM t` reaches this path precisely because rawQuery only ran the first statement and got zero rows back — so the probe would then execute the DELETE for real as a "harmless" side effect of inferring column names. Added sqliteHasMultipleStatements, a small scanner (string/quoted-identifier and comment aware) that detects a real second statement after a top-level `;`, and skip the TEMP VIEW probe entirely when it's true, falling back to the existing single-table schema lookup instead.
ZhuchkaTriplesix
deleted the
issue/1005-sqlite-infer-columns-multi-statement
branch
September 28, 2026 08:11
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #1005:
SqliteConnection.inferQueryColumnsprobes zero-row queries by wrapping the user's SQL inCREATE TEMP VIEW ... AS <sql>viaDatabase.execute, which (unlikerawQuery) runs every statement it's given. A query likeSELECT * FROM t WHERE 0; DELETE FROM treaches this path precisely becauserawQueryonly ran the first statement and got zero rows back — so the probe would then execute the DELETE for real as a "harmless" side effect of inferring column names for the grid.Fix
Added
sqliteHasMultipleStatements(lib/core/database/sqlite_sql.dart), a small string/quoted-identifier/comment-aware scanner that detects a real second statement after a top-level;.inferQueryColumnsnow skips the TEMP VIEW probe entirely when the text has more than one statement, falling back to the existing single-table schema lookup instead (which never executes the query text).Test plan
sqliteHasMultipleStatements(single statement w/ trailing;/;;, real second statement, semicolons inside strings/quoted identifiers/comments not counted)DELETEsmuggled after aWHERE 0no longer runs viainferQueryColumns. Verified this test fails without the fix (temporarily disabled the new check, confirmed the DELETE runs, restored the fix).flutter analyze— no issuesflutter testsuite (1865 tests) — all passing