Skip to content

fix(sqlite): recognize single statements with SQLite parser - #45

Merged
fffonion merged 1 commit into
masterfrom
fix/sqlite-single-statement-triggers
Nov 24, 2026
Merged

fffonion merged 1 commit into
masterfrom
fix/sqlite-single-statement-triggers

Conversation

@fffonion

Copy link
Copy Markdown
Collaborator

What

normalized_sql decided statement boundaries by counting semicolons, so any
CREATE TRIGGER ... BEGIN ...; END body looked like multiple statements and the
host rejected legal trigger DDL before it ever reached SQLite.

This rebases the dangling b5066dd work onto current master and replaces that
lexical boundary check with a parse-time probe:

  • check_single_statement prepares exactly one statement on the executing
    connection (same authorizer, limits and progress handler), finalizes it without
    stepping, and then allows only whitespace or complete comments after the parsed
    statement. A second statement now fails as MultipleStatement, which
    sqlite_error maps back to the existing multiple SQLite statements are not allowed
    message on every route.
  • normalized_sql keeps its lexical safety checks (quotes, comments, NUL, size) but
    no longer treats ; as a statement terminator; bracket-quoted identifiers are
    handled like the other quote forms.
  • Trigger support requires no authorizer change: the current policy already allows
    CreateTrigger and the trigger body's own DML/read actions through its default
    allow, while Attach/Detach/Pragma/virtual-table/load_extension denials are
    untouched.

Tests

builtins::runtime::sqlite::tests::* with --features sqlite (12 passed), including two
new cases:

  • single_statement_gate_accepts_trigger_bodies_and_rejects_tails — trigger bodies
    parse, trailing whitespace/comments are accepted, and a second statement or DDL
    after the trigger is still MultipleStatement.
  • trigger_body_executes_and_bumps_the_stored_revision — the gated execute path
    creates a second trigger and an insert fires both.

cargo +1.99.1 fmt --all -- --check and
cargo +1.99.1 clippy --locked --features sqlite --lib -- -D warnings are clean.

The original commit also carried tests/sqlite_single_statement_tests.rs; that file
predates the current typed SqliteOpenOptions/Option dialect, so it is omitted here
rather than merged as a failing file. Trigger coverage lands in the module tests above.

@fffonion
fffonion force-pushed the fix/sqlite-single-statement-triggers branch from b866e2f to 5379463 Compare November 23, 2026 11:30
fffonion added a commit to rustscript-lang/rustscript-agent that referenced this pull request Nov 24, 2026
The pinned Core lexer treated a trigger body's semicolons as separate statements,
so legal CREATE TRIGGER DDL was refused on every route. rustscript-lang/rustscript#45
replaces that lexical boundary check with a parse-time probe; pin to its head
(5379463) until it merges.
@fffonion
fffonion merged commit 11c9ee9 into master Nov 24, 2026
8 checks passed
@fffonion
fffonion deleted the fix/sqlite-single-statement-triggers branch November 24, 2026 11:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant