Skip to content

fix: count returned rows in history for statements with a result set - #22

Merged
matej21 merged 2 commits into
mainfrom
fix/history-row-count
Nov 2, 2026
Merged

matej21 merged 2 commits into
mainfrom
fix/history-row-count

Conversation

@matej21

@matej21 matej21 commented Nov 2, 2026 •

Copy link
Copy Markdown
Member

CI on main broke when oven-sh/setup-bun started installing Bun 1.4.4. rpc-handlers > query.execute automatically logs to history now fails, because a SELECT 1 is logged with rowCount: 0.

Cause

History and the session log record affectedRows ?? rowCount. Bun.SQL reports affectedRows for every statement, including 0 for a SELECT:

Bun PostgreSQL SELECT MySQL SELECT SQLite SELECT
1.3.14 null 0 null
1.4.4 0 0 0

So a read was always logged as 0 rows on MySQL, and since Bun 1.4 on PostgreSQL and SQLite too.

Fix

statementRowCount() in @dotaz/shared/query-result counts what a statement returned when it produced a result set, and what it changed otherwise. This is the same split the result panel already makes on columns.length. It replaces the expression in all four places that summed it:

  • backend history
  • session log
  • demo adapter
  • frontend history entry

Verified

  • New test: history counts returned rows for a read and changed rows for a write.
  • The unit suite passes under both Bun 1.3.14 and 1.4.4 (1349 pass, 0 fail).
  • lint, format and tsc are clean.

Status

🤖 Generated with Claude Code

History and the session log summed `affectedRows ?? rowCount`. Drivers
report `affectedRows: 0` for a SELECT — MySQL always did, and since Bun
1.4 Bun.SQL does the same for PostgreSQL and SQLite — so a read was
logged as touching 0 rows. CI picked up Bun 1.4.4 and the history test
started failing on main.

`statementRowCount` counts what a statement returned when it produced a
result set, and what it changed otherwise. The backend history, session
log, demo adapter and the frontend history entry all use it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@matej21

matej21 commented Nov 2, 2026

Copy link
Copy Markdown
Member Author

Review round 1 — 751c9a9

Reviewer: independent Claude Code subagent (Claude Opus). Ran real statements against PostgreSQL, MariaDB and SQLite on Bun 1.3.14 and 1.4.4.
Verdict: approve

The fix is correct for all three Bun.SQL drivers on both Bun versions. Cases checked:

  • zero-row SELECT
  • INSERT/DELETE … RETURNING
  • EXPLAIN and SHOW
  • SET and DDL
  • error, cancelled and timeout results
  • multi-statement runs

No other site sums the old idiom.

Findings

  1. low — demo driver reports a stale affectedRows (predates this PR). src/frontend-demo/wasm-sqlite-driver.ts:104 uses this.db.changes(), which keeps the last write's count. After INSERT … VALUES (1),(2),(3), a zero-row SELECT, CREATE INDEX or PRAGMA reports 3, and demo mode shows "3 rows affected". The fix belongs in that driver.
  2. low — test coverage. The new test runs on SQLite and covers history only. On Bun 1.3 it would pass without the fix. A zero-row SELECT case would pin the fallback branch.
  3. nit — doc comment. statementRowCount says "produced a result set", but columns is built from the first row, so the check means "returned at least one row".
  4. nit. SqlResultPanel.tsx still writes affectedRows ?? rowCount inline under columns.length === 0. This is equivalent to the helper's fallback branch.
  5. nit. The src/shared/CLAUDE.md structure list does not mention query-result.ts.

Also say what the columns check actually means and list query-result.ts
in the shared module map.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@matej21

matej21 commented Nov 2, 2026

Copy link
Copy Markdown
Member Author

Response to review round 1

  1. low — stale affectedRows in the demo driver: won't fix here. This predates the PR and lives in wasm-sqlite-driver.ts, which this PR does not touch. It needs its own fix: report the change delta, or 0 for statements that return columns.
  2. low — coverage: fixed in 9f9dc75. Added a zero-row SELECT case, which pins the fallback branch. CI runs Bun 1.4.4, where the test fails without the fix.
  3. nit — doc comment: fixed in 9f9dc75. It now says "returned rows" and explains the zero-row fallback.
  4. nit — SqlResultPanel inline idiom: won't fix. It sits under columns.length === 0, where it is equivalent to the helper.
  5. nit — src/shared/CLAUDE.md: fixed in 9f9dc75.

@matej21
matej21 merged commit 7654870 into main Nov 2, 2026
2 checks passed
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