Skip to content

fix: SQLite scripts, safe schema reads, row cap - #934

Merged
EVWorth merged 5 commits into
mainfrom
claude/hopeful-bardeen-1k4d1h
Oct 30, 2026
Merged

EVWorth merged 5 commits into
mainfrom
claude/hopeful-bardeen-1k4d1h

Conversation

@EVWorth

@EVWorth EVWorth commented Oct 30, 2026

Copy link
Copy Markdown
Owner

SQLite fixes, done by two implementer-rust lanes.

Closes #928
Closes #929
Closes #932
Closes #933

Changes

  • fix: sqlite_execute runs only the first statement #928: scripts run every statement. Before, only the first statement ran, and the run still reported success.
    • The new mas-sqlite/src/split.rs is a pure-Rust copy of SQLite's own sqlite3_complete state machine. It does not split inside strings, quoted names or comments, and keeps a trigger body (BEGIN … END) as one statement.
    • Statements run in order, each prepared after the previous one has run.
    • SqliteQueryResult gains sql, the text of that statement.
    • A failure stops the run and reports statementIndex and completedResults, as MySQL does.
  • fix: SQLite schema reads interpolate table names #929: schema reads no longer interpolate names.
    • get_columns uses pragma_table_info(?1) with the name bound.
    • The row count quotes the name, doubling any ". Before, a crafted table name in an opened file could inject SQL; a test shows that a name built to run a DROP no longer does.
    • Index columns come from pragma_index_list / pragma_index_xinfo, not from parsing CREATE INDEX text.
  • fix: SQLite errors marked with the MySQL splitter #932: the right statement is marked on failure. failedStatementOf now splits SQLite scripts with a shared TS SQLite splitter (src/lib/sqlite-split.ts); the mock uses the same splitter.
  • fix: SQLite queries have no row cap #933: SQLite results are capped.
    • sqlite_execute takes limit and offset. The executor stops at the limit and sets truncation_reason.
    • It has the same free-memory guard as MySQL. When the guard trips, the rest of the script does not run.
    • Paging now works on SQLite: before, the offset was ignored, so Next showed the first page again.
    • Results report whether a transaction is open (is_autocommit()). The TX badge stays MySQL-only for now, because one SQLite connection is shared by every tab.
    • sysinfo moves into the workspace dependencies.

Tests

  • Rust:
    • splitter: 10 cases;
    • executor: multiple statements, failure index, trigger bodies, ; inside strings, RETURNING, limit, offset, memory guard, transaction state;
    • command error payload;
    • schema reads with names containing " and ;, DESC and COLLATE columns, an expression index, and the injection attempt.
  • TS: tests for the shared splitter, the failed-statement marking (a trigger before the failure), the API wrapper, the data source, and the mock.
  • cargo fmt and clippy with -D warnings are clean. cargo test -p mas-sqlite and -p sqlpilot pass. npm run test:unit passes (3741 tests). After merging main, npm run type-check and vitest on src/{dev,lib,stores} pass. npm run lint has 0 errors. npx dprint check is clean.

Generated by Claude Code

The SQLite executor handed the whole script to rusqlite's prepare, which
compiles only the first statement and ignores the rest, so a script ran
its first statement and reported success.

The script is now split as SQLite splits it: a port of sqlite3_complete's
state machine that respects strings, quoted names, comments and trigger
bodies. Each statement is prepared after the previous one has run and
gets its own result, carrying its text in a new `sql` field. The first
failure stops the run and is reported with its statement index and the
results of the statements before it, as the MySQL path does. The mock
splits with the same state machine.

Closes #928

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WTypK4RjzzdjoFxd3qk14g
get_columns built `PRAGMA table_info("{}")` and the row count in
get_tables built `SELECT COUNT(*) FROM "{}"`, both without doubling a
`"` in the name, so an odd name broke the read and a crafted name in an
opened file could inject SQL. Columns now come from pragma_table_info
with the name bound; the count quotes the name properly against main.

get_indexes parsed the CREATE INDEX text, which split expression
indexes and COLLATE/DESC columns wrongly. It now reads
pragma_index_list (user-created indexes only) and pragma_index_xinfo
(key columns in key order, an expression as "<expression>").

Closes #929

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WTypK4RjzzdjoFxd3qk14g
The failed-statement highlight split every script with the MySQL
splitter, so a SQLite trigger body cut at its inner semicolons and the
statement text and "N of M" count went wrong. The SQLite splitter moves
from the mock into src/lib/sqlite-split.ts, shared by the mock and the
result store, which now picks the splitter by connection kind.

Closes #932

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WTypK4RjzzdjoFxd3qk14g
The SQLite executor read every row and never set rows_truncated, so a
SELECT * on a large table loaded it all and sent it over IPC.
sqlite_execute now takes the row limit and page offset execute_query
takes, applies them while stepping, stops on low free memory as the
MySQL executor does, and reports truncation_reason. Paging works on
SQLite tabs as a result, where the offset used to be ignored.

Each result also reports in_transaction from is_autocommit(), mapped
to QueryResult.transaction by the data source.

Closes #933

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WTypK4RjzzdjoFxd3qk14g
@EVWorth
EVWorth merged commit bcaa859 into main Oct 30, 2026
12 checks passed
@EVWorth
EVWorth deleted the claude/hopeful-bardeen-1k4d1h branch October 30, 2026 12:13
@EVWorth EVWorth mentioned this pull request Oct 30, 2026
@github-actions github-actions Bot mentioned this pull request Nov 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants