Skip to content

ADFA-7297 SQLite debugger P2-2: rows, change counts, named parameters and column types - #2319

Open
davidschachterADFA wants to merge 9 commits into
sqlite-debugger/ADFA-7296from
sqlite-debugger/ADFA-7297
Open

davidschachterADFA wants to merge 9 commits into
sqlite-debugger/ADFA-7296from
sqlite-debugger/ADFA-7297

Conversation

@davidschachterADFA

@davidschachterADFA davidschachterADFA commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

ADFA-7297

Phase 2, P2-2 of the SQLite debugger (ADFA-7131): the MCP server turns on the row recording that #2311 (P2-1) added to the extension, and returns rows, change counts, named parameters and column types. Stacked on #2311.

What it does (subprojects/sqlite-debugger)

  • get_events: a profile event gains rows, changes (null for a read) and rows_cut. A new row event kind has row_number, column_count, values, storage_classes and cut_values. Calling get_events turns row recording on: 10 rows per statement, values cut at 256 bytes, rows at 4 KiB. include_rows: false turns it off and leaves row events out. Recording also goes off when the client goes idle and when the server stops.
  • query and explain_query_plan: args can be an object that binds by name (:name, @name, $name, ?NNN). A key is written as in the SQL; a key without a prefix, such as id, matches :id, @id and $id, and a ?NNN key keeps its ?. Names are matched in JNI. Every parameter needs a value, and every key must name a parameter.
  • query returns column_types (the declared types) and storage_classes (one letter per cell, irtbn).
  • BLOBs are now {hex, bytes, truncated}; they were base64. No client reads the old key.
  • The README's "Limits" and tool sections describe each of these.

Limit: execute (#2312) still binds positional args only. Whichever of #2312 and this PR merges second wires named args into execute: pass argNames through bridge_execute and prepare_bound.

Commits

  • 99007a7: the change, from the cloud session.
  • e73b348: spotlessApply on DatabaseTools.kt only (one call chain wrapped, one blank line dropped).
  • e450122: the args description said every key could drop its prefix, but a bare 1 doesn't match ?1; it now says a ?NNN key keeps its ?, as the README already did (from the review below).
  • a8fca8c: merges the cloud session's ffb3f18, which drops a stale comment in sqlitedbg_jni.c; ADFA-7301 SQLite debugger P2-6: sqlite3 shell tools (suggest_indexes, lint_foreign_keys, dump, export, .dbinfo) #2323 carries the same commit.
  • e648501: test formatting only. ktlint joined kinds()'s expression body onto its signature line, at 142 columns, and that error (reported at L1) stopped its other changes. kinds() now has a block body, and the lines ktlint wanted wrapped are wrapped. Production code is unchanged.
  • f0c931f (ADFA-7323): on the J7, a misspelt key ({"idx": 1} for :id) failed with only "no value was given for parameter :id". bind_named stopped at the first parameter with no value, before it looked for keys that matched nothing. It now names the key as well: "the statement has no parameter named idx, and no value was given for parameter :id". A parameter left out with no stray key, and a stray key with every parameter bound, keep their messages. The README says so.
  • d354698: merges ADFA-7296: SQLite debugger records row and change events #2311's 0c9a19e, the 2026-11-26 review's fake-engine fix (ADFA-7131 comment 41632). One conflict: both branches added an addEvent overload to FakeDebugEngine, and both are kept.
  • b87338e: merges ADFA-7296: SQLite debugger records row and change events #2311's 2d674ec, its fix for CodeRabbit's third review (EventDecoder refuses a row count its bytes cannot hold), with no conflicts. Its diff is exactly 2d674ec's.

Tests

  • At b87338e: :subprojects:sqlite-debugger:testDebugUnitTest (125 tests) and spotlessCheck pass.
  • At d354698: :subprojects:sqlite-debugger:testDebugUnitTest (124 tests) and spotlessCheck pass.
  • Local: test.sh at 99007a7 passes (ASan+UBSan 20750 checks, TSan 20732, JNI 279, 0 failures). The C and JNI code is unchanged after it. At e648501: :subprojects:sqlite-debugger:testDebugUnitTest (123 tests) and spotlessCheck pass. assembleV8Debug passed at 99007a7, and :subprojects:sqlite-debugger:assembleDebug at e450122.
  • At f0c931f: test.sh passes (ASan+UBSan 20748 checks, TSan 20750, JNI 280, 0 failures), and so do :subprojects:sqlite-debugger:testDebugUnitTest (123 tests), spotlessCheck and the module's debug and release AARs. Revert proof: with sqlitedbg_jni.c as at a8fca8c, exactly the two changed expectations fail, each showing the old message.
  • From the cloud session at 99007a7: test.sh 0 failures, 118 JVM tests, and four revert proofs that fail as named.

Review before this PR (a fresh read of 99007a7; no CRITICAL or IMPORTANT findings):

  • Fixed: the args description (e450122).
  • Not changed (MINOR): error messages cut a parameter name at 100 bytes (%.100s), which can split a UTF-8 character and show U+FFFD; a comment in DatabaseTools.kt says every tool that returns cells carries storage_classes, but only query and get_events do; the named-binding tests don't cover a key over 100 bytes or names and args of different lengths (the code paths were read and found correct).

Device check (Galaxy J7, Android 9, 2026-11-26; ADFA-7297 41611): get_events turned row recording on; after a note was added in the app, the INSERT's profile event had changes 1 and the list's SELECT rows 5, followed by 5 row events, and include_rows: false left them out. Named args bound as id, :id and ?1, and a misspelt key failed with "no value was given for parameter :id" (the key itself is now named too, f0c931f; not rerun on the device). The test app was RoomNotes built with the SQLite debugger from #2323's head (which carries this PR) and #2262's plugin, called over adb forward.

No screens added or changed.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn


Code Reviewer: Code Reviewer couldn't review this pull request
The pull request author does not have access to AI for the associated Atlassian organization.

claude and others added 5 commits November 26, 2026 05:02
…column types

Phase 2, P2-2 (ADFA-7131 comments 41476, 41477). On P2-1 (#2311, at
e16ea45).

- get_events: a profile event carries rows, changes (null for a read)
  and rows_cut; a row event carries row_number, column_count, values,
  storage_classes and cut_values. get_events turns row recording on
  (new DebugEngine.setRowCapture, JNI setRowCapture): 10 rows per
  statement, values cut at 256 bytes, a row at 4 KiB. include_rows
  false turns it off and leaves row events out; it also goes off with
  the idle client and when the server stops.
- query and explain_query_plan: args as an object binds by name
  (:name, @name, $name, ?NNN; a key with or without its prefix). Names
  go to JNI as UTF-8 and are matched against
  sqlite3_bind_parameter_name: every parameter needs a value and every
  key a parameter. The array form is unchanged.
- query returns column_types (sqlite3_column_decltype, null for an
  expression) and storage_classes, a letter per cell (i r t b n): JSON
  writes REAL 2.0 as 2, and big integers as strings.
- BLOBs are {hex, bytes, truncated}; they were base64. No client reads
  the old key (AI-Agent-MCP passes results through).
- Tool descriptions say what is capped; README updated.

Limit: execute (P2-3, #2312) still binds positional args only; the
second of the two PRs to merge wires its names.

Tests: test.sh passes (ASan+UBSan, TSan, JNI 279 checks: each name
form, the five refusals, declared types, the row-recording switch).
DatabaseToolsTest, McpProtocolTest and EventDecoderTest pass (118),
compiled with the Kotlin compiler outside Gradle, including an encoding
of every event in P2-1's fixture. Revert proofs: no unused-name check
fails "named: a misspelt name"; no decltype fails "declared types";
no idle switch-off fails rowRecordingStopsWithTheIdleClient; no row
filter fails getEventsTurnsRowRecordingOnUnlessToldNotTo. Not run here:
Gradle, spotlessCheck, a device.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAZ8yszEP4MqbR9PLba
spotlessKotlinCheck's two changes to DatabaseTools.kt: the named-args
key chain on one call per line, and one blank line dropped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
The args description said every key could be written without its
prefix, but only :name, @name and $name match a bare name (key_matches):
{"1": 5} for ?1 fails with "no value was given for parameter ?1". The
text now says a ?NNN key keeps its ?, as the README already does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
It described bind_args, which bind_positional and bind_value replaced.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAZ8yszEP4MqbR9PLba
spotlessKotlinCheck failed on DatabaseToolsTest.kt with one
max-line-length error, reported at L1. ktlint joins kinds()'s expression
body onto its signature line, and the joined line is 142 columns. Its
other changes were then not applied either, so the file also needed
ktlint's wrapping of the named-args call and of a four-call chain.

kinds() now has a block body. Two long assertions are wrapped, and the
row-values check reads values.get(c) once, before its when, so each
branch stays on one line. Production code is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review for a one-time review, or @claude review always to subscribe this PR to a review on every future push.

Tip: disable this comment in your organization's Code Review settings.

The cloud session's ffb3f18 drops a stale comment above bind_value in
sqlitedbg_jni.c (one line). P2-6 (ADFA-7301) already merges it, so the
two branches keep the same ancestry. No conflicts; nothing else changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
davidschachterADFA pushed a commit that referenced this pull request Nov 26, 2026
…ite-debugger/ADFA-7301

P2-6 now stacks on #2319: it takes Remington's e450122 (a ?NNN args key
keeps its ?), e648501 and the merge of ffb3f18. No conflicts. At
the merge: DatabaseToolsTest, ShellToolsTest, McpProtocolTest and
EventDecoderTest pass (135); test.sh 0 failures (JNI 333).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAZ8yszEP4MqbR9PLba
bind_named stopped at the first parameter with no value, before it
looked for keys that matched no parameter. So args {"idx": 1} against
"WHERE id = :id" failed with "no value was given for parameter :id",
and the misspelt key was never named (seen on the J7, ADFA-7297
comment 41611).

It now binds every parameter that has a value, then reports a key that
matched nothing first, together with the parameter left without a
value: "the statement has no parameter named idx, and no value was
given for parameter :id". A parameter left out with no stray key, and a
stray key with every parameter bound, keep their messages.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
davidschachterADFA added a commit that referenced this pull request Nov 26, 2026
…qlite-debugger/ADFA-7301

Brings in the misspelt named-args key message from #2319.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
davidschachterADFA pushed a commit that referenced this pull request Nov 26, 2026
…eff47b0)

The base for ADFA-7304, which needs P2-2 and P2-3/P2-4; neither has
landed (David, 2026-11-26).

Conflicts, each side kept:
- sqlitedbg.c: P2-2's sqlitedbg_set_row_capture beside P2-3's PRAGMA
  allowlist and writable authorizer.
- sqlitedbg_jni.c: P2-3's prepare_bound calls P2-2's bind_named or
  bind_positional (which checks the count itself, as prepare_bound did);
  bridge_query passes its names; execute stays positional for now.
- DebugEngine.kt: P2-2's setRowCapture beside P2-3's openServerConnection doc.
- DatabaseTools.kt: P2-3's withConnection with P2-2's Bind; execute
  refuses object args (its schema still says array), so an object's values
  are never bound by position; the Room check passes Bind.NONE.
- README: the JNI test list names both PRs' cases.

At the merge: test.sh 0 failures (JNI 480); DatabaseToolsTest,
McpProtocolTest and EventDecoderTest pass (131).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAZ8yszEP4MqbR9PLba
davidschachterADFA pushed a commit that referenced this pull request Nov 26, 2026
The item left for whichever of #2312 and #2319 merged second (41592):
execute takes args as an array or an object, through the same
prepare_bound, bind_named and argsSchema as query.

- JNI execute gains names ([[B); bridge_execute passes them to
  prepare_bound. ServerConnection.execute gains argNames.
- The execute tool's args schema is argsSchema(), and the merge's
  refusal of an object is gone. README updated.

Tests: JNI binds INSERT ... VALUES(:id, @s) by name and refuses a
misspelt key with SQLITE_RANGE, writing nothing;
executeBindsAnObjectByName. test.sh 0 failures (JNI 488); JVM 132.
Revert proof: execute ignoring names fails "each value went to its own
parameter", "execute ran with a misspelt name" and "and the row is
still there".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAZ8yszEP4MqbR9PLba

@davidschachterADFA davidschachterADFA left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of #2319 at f0c931f63f. Stack: #2311 (P2-1) <- #2319 (this) <- #2323 (P2-6); claims checked at the stack tip 323d3d3. Read: the full diff; at the tip DatabaseTools.kt, EventDecoder.kt, the sqlitedbg.c row-capture setters, the JNI named-arg matching (misspelt, duplicate and unused keys) and decltype handling, and the README. Tests were not re-run for this review.

No findings survived verification.
Earlier review comments, re-checked against the code (not the replies)

  • claude[bot] - review-bot boilerplate (manual review instructions); no findings: fixed. Review body only says reviews are manual; no inline comments exist on the PR (gh api pulls/2319/comments is empty).

Verdict: COMMENT. This PR is authored by the account posting the review, and GitHub refuses APPROVE and REQUEST_CHANGES on your own PR. Severity rules: CodeOnTheGo REVIEW.md and CLAUDE.md (a ticket moves to QA with no outstanding critical, high or medium findings); addons has no written rule, so the default applied.


Generated by Claude Code

…gger/ADFA-7297

Brings in the #2311 review fix (the fake engine sizes records as the native ones).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
davidschachterADFA added a commit that referenced this pull request Nov 26, 2026
…gger/ADFA-7301

Brings in the #2311 review fix through #2319.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
@davidschachterADFA

Copy link
Copy Markdown
Collaborator Author

@hal-eisen-adfa A new commit since you were asked to review: d354698 merges #2311's test-only fix for the 2026-11-26 review. Both branches had added an addEvent overload to FakeDebugEngine, and both are kept. This PR had no findings of its own.

…gger/ADFA-7297

Brings in the #2311 review fix (EventDecoder refuses a row count its bytes cannot hold).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
davidschachterADFA added a commit that referenced this pull request Nov 27, 2026
…gger/ADFA-7301

Brings in the #2311 review fix through #2319.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
davidschachterADFA added a commit that referenced this pull request Nov 27, 2026
…gger/ADFA-7302

Brings in the #2311 review fix through #2319 and #2323.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
@davidschachterADFA

Copy link
Copy Markdown
Collaborator Author

@hal-eisen-adfa A new commit since you were asked to review: b87338e merges #2311's 2d674ec (EventDecoder refuses a row count its bytes cannot hold), with no conflicts. Its diff is exactly 2d674ec's. This PR has no change of its own.

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.

2 participants