Repository navigation
fix(cli): print rows for every returning statement in db execute - #864
Conversation
Local `void db execute` printed results only when the SQL started with `SELECT`, so `WITH`, `PRAGMA`, `EXPLAIN` and `RETURNING` succeeded silently. The remote D1, PostgreSQL and MySQL paths already print rows for any statement that returns them. Ask better-sqlite3 whether the prepared statement reads rows instead of matching the statement text, and leave a multi-statement script on `exec()`, which reports no rows.
|
👁️🗨️ Review this pull request with grouped, summarized diffs at: raw result💭 analyzed by {
"headSha": "eb919dff6844998d123c05e5cc7a4903ce1bec64",
"result": {
"overallSummary": "Fixes the local `db execute` output: rows were printed only when the SQL text started with `SELECT`, so `WITH`, `PRAGMA`, `EXPLAIN` and `RETURNING` succeeded silently. The local path now asks better-sqlite3 whether the prepared statement reads rows (`statement.reader`), matching the remote D1/PostgreSQL/MySQL behavior. **Review order:** the CLI change first, then the tests that pin it, then the one-line doc update.",
"groups": [
{
"key": "local-execute-rows",
"label": "Local execute row printing",
"summary": "Classify the statement by what SQLite reports (`statement.reader`) instead of a `^SELECT` regex, so any row-returning statement prints a table and writes/DDL stay silent. Multi-statement scripts still fall back to `exec()`. The comment/semicolon stripping used by the safety check is extracted into `stripSqlDecoration`, and the sqlite statement type gains the `reader` flag that this relies on.",
"category": "cli",
"filePaths": [
"packages/void/src/cli/db.ts",
"packages/void/src/migrations/runner.ts"
],
"critical": false,
"fileNotes": [
{
"path": "packages/void/src/cli/db.ts",
"text": "Two behavior changes beyond the printed rows: the `No rows returned.` info message is gone (empty results are now silent, like the remote paths), and a failing `prepare()` no longer surfaces when the SQL contains a semicolon - it is re-run through `exec()` instead, which also swallows the fact that nothing was printed."
},
{
"path": "packages/void/src/migrations/runner.ts",
"text": "Type-only addition documenting the better-sqlite3 statement shape; no runtime change."
}
]
},
{
"key": "tests",
"label": "Execute tests",
"summary": "New cases run the unmocked local SQLite path against a real database file so `reader` is exercised for real: `WITH ... SELECT`, `PRAGMA`, `EXPLAIN QUERY PLAN`, a `SELECT` behind a comment and `INSERT ... RETURNING` print tables, while writes, DDL, empty results and multi-statement scripts print nothing.",
"category": "tests",
"filePaths": [
"packages/void/test/unit/db-commands.test.ts"
],
"fileNotes": [
{
"path": "packages/void/test/unit/db-commands.test.ts",
"text": "`tableOutput()` drops blank lines because `runDbCommand` prints a leading blank line, so it only sees actual table output; the two-statement script test also reopens the database to confirm the script really ran."
}
]
},
{
"key": "docs",
"label": "Docs wording",
"summary": "Reword the `void db execute` reference to describe the new contract: row-returning statements print a table, writes are silent, and multi-statement SQL runs as a script without results.",
"category": "docs",
"filePaths": [
"docs/reference/cli/database.md"
]
}
],
"schemaVersion": 1,
"source": "llm",
"generatedAt": "2026-11-17T06:20:57.979Z",
"model": "openai-compatible/opencode-go/deepseek-v4.1-flash",
"locale": "en"
}
} |
cpojer
left a comment
There was a problem hiding this comment.
two issues:
- Failed writes can execute twice because the catch block in db.ts retries through
exec. With UPDATE OR FAIL … SET count=count+1, note='a;b', a constraint failure on the second row leaves the first row incremented twice. - Scripts containing quoted comment markers fail. Two inserts where the first value is '--' fail here without inserting either row. The regex mistakes string contents for comments and hides statement separators; '/' and '/' reproduce it too. We should use SQLite’s preparation result instead.
|
Let me fix it |
Telling a script from a single statement by scanning the SQL text replayed a partially applied write, because the catch also wrapped execution, and missed statement separators behind literals such as '--' or '/*'. Ask better-sqlite3 instead: it refuses SQL that holds no statement or more than one with a RangeError before running anything, so only that refusal falls back to exec().
|
They both came from the same mistake that I used the statement text to tell a script from a single statement, and wrapped the execution in the same catch. Fixed now. The catch now wraps only Added tests for |
Fixes #862
Description
Local
void db executeprinted rows only when the SQL started withSELECT, soWITH,PRAGMA,EXPLAINandRETURNINGran and reported success with no output. The remote D1, PostgreSQL and MySQL paths already print rows for any statement that returns them.The local path now asks better-sqlite3 whether the prepared statement reads rows (
statement.reader) and prints the table when it does, instead of matching the statement text. Writes and DDL stay silent. A script with several statements still runs throughexec(), which reports no rows, and the reference docs now say so.Test
Tests in
packages/void/test/unit/db-commands.test.tsrun the local SQLite path against a real database file.WITH ... SELECT,PRAGMA database_list,EXPLAIN QUERY PLAN, aSELECTbehind a leading comment andINSERT ... RETURNINGprint a table.INSERT,CREATE TABLEand an empty result print nothing. A two-statement script runs without output, andSELECT 'a;b'stays one statement.Same command on both branches: