Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
67355bd
ADFA-7296 SQLite debugger: record row and change events in the extension
claude Nov 25, 2026
02c384f
ADFA-7296 Apply spotless formatting to EventDecoder and its test
davidschachterADFA Nov 25, 2026
ce76bcb
ADFA-7296 Don't read row text through a NULL pointer when SQLite is o…
davidschachterADFA Nov 25, 2026
76be5b0
ADFA-7296 Cap max_row_bytes at 64 KiB so a row record always fits a r…
davidschachterADFA Nov 25, 2026
8592704
ADFA-7296 README: the row limit's cap and the measured cost of counti…
davidschachterADFA Nov 25, 2026
490feb0
ADFA-7296 README: the row event kind and interface version 3
davidschachterADFA Nov 25, 2026
4f971a8
ADFA-7296 EventDecoderTest: make the 4-byte number case reach the wid…
davidschachterADFA Nov 25, 2026
e16ea45
ADFA-7296 Merge origin/stage at 661279963 into sqlite-debugger/ADFA-7296
davidschachterADFA Nov 26, 2026
99007a7
ADFA-7297 SQLite debugger: rows, change counts, named parameters and …
claude Nov 26, 2026
e73b348
ADFA-7297 style: spotless reformat, no functional change
davidschachterADFA Nov 26, 2026
e450122
ADFA-7297 SQLite debugger: say which args keys may drop their prefix
davidschachterADFA Nov 26, 2026
ffb3f18
ADFA-7297 sqlitedbg_jni.c: drop a stale comment above bind_value
claude Nov 26, 2026
e648501
ADFA-7297 style: test lines ktlint can format, no functional change
davidschachterADFA Nov 26, 2026
a8fca8c
ADFA-7297 Merge ffb3f18420 into sqlite-debugger/ADFA-7297
davidschachterADFA Nov 26, 2026
f0c931f
ADFA-7323 SQLite debugger: name a misspelt named-args key in the error
davidschachterADFA Nov 26, 2026
50f78a6
ADFA-7304 Merge sqlite-debugger/ADFA-7297 (#2319, f0c931f63) into #23…
claude Nov 26, 2026
346cd6c
ADFA-7304 SQLite debugger: execute binds named args, as query does
claude Nov 26, 2026
6f5a8a4
ADFA-7304 SQLite debugger: execute returns RETURNING rows within quer…
claude Nov 26, 2026
64c3ce5
ADFA-7304 style: spotlessApply on DatabaseToolsTest.kt, no functional…
davidschachterADFA Nov 26, 2026
a8bb4e3
ADFA-7304 JniQueryTest: the time-limit case survives a busy machine
davidschachterADFA Nov 26, 2026
c2fae14
ADFA-7304 execute: say how many rows a failed FAIL statement kept
davidschachterADFA Nov 26, 2026
0c9a19e
ADFA-7296 test: size the fake engine's records as the native ones
davidschachterADFA Nov 26, 2026
d354698
ADFA-7297 Merge sqlite-debugger/ADFA-7296 at 0c9a19ea3 into sqlite-de…
davidschachterADFA Nov 26, 2026
2d674ec
ADFA-7296 EventDecoder: refuse a row count its bytes cannot hold
davidschachterADFA Nov 27, 2026
b87338e
ADFA-7297 Merge sqlite-debugger/ADFA-7296 at 2d674ecfc into sqlite-de…
davidschachterADFA Nov 27, 2026
5dbd5c3
ADFA-7304 Merge sqlite-debugger/ADFA-7299 (#2313, 07e7ccd38) into sql…
davidschachterADFA Nov 30, 2026
9aa25e7
ADFA-7304 Merge sqlite-debugger/ADFA-7297 (#2319, b87338e97) into sql…
davidschachterADFA Nov 30, 2026
571cc3f
ADFA-7304 execute: classify a commit stopped at the cap like a stalle…
davidschachterADFA Nov 30, 2026
f7e7b55
ADFA-7304 tests: reset-commit stall, conflict modes with RETURNING, a…
davidschachterADFA Nov 30, 2026
0d5dbb9
ADFA-7304 execute: describe truncated_cell_indexes as query does
davidschachterADFA Nov 30, 2026
5ee892b
ADFA-7304 tests: halve the table when the first step passes the limit…
davidschachterADFA Nov 30, 2026
9cb70b8
ADFA-7304 Merge sqlite-debugger/ADFA-7299 (#2313, a1d383d81) into sql…
davidschachterADFA Nov 30, 2026
b9ccfc7
ADFA-7304 tests: size the RETURNING time-limit table both ways, so a …
davidschachterADFA Nov 30, 2026
9530161
ADFA-7304 execute: say whether the write committed when building the …
davidschachterADFA Nov 30, 2026
4d02e99
ADFA-7304 Align execute docs and tool text with best-effort limits an…
davidschachterADFA Nov 30, 2026
b1c4e54
ADFA-7304 JNI test: require rows copied when the RETURNING time limit…
davidschachterADFA Nov 30, 2026
5d8acf6
ADFA-7296 Fix CodeRabbit findings: no big-blob reads, unknown changes…
davidschachterADFA Dec 1, 2026
67e3017
ADFA-7304 DatabaseToolsTest: check the reworded execute text in the e…
davidschachterADFA Dec 1, 2026
bad9f58
Merge sqlite-debugger/ADFA-7296 (#2311 at 5d8acf62d) into ADFA-7304
davidschachterADFA Dec 1, 2026
2aa2c37
Merge sqlite-debugger/ADFA-7296 (#2311 at 5d8acf62d) into ADFA-7297
davidschachterADFA Dec 1, 2026
acd87a1
ADFA-7304 execute: say truly what became of a write whose call failed
davidschachterADFA Dec 1, 2026
dd7ee19
ADFA-7296 README: a query inside a leftover transaction can read stale
davidschachterADFA Dec 1, 2026
2523485
Merge sqlite-debugger/ADFA-7296 (#2311 at dd7ee1953) into ADFA-7297
davidschachterADFA Dec 1, 2026
75af55f
Merge sqlite-debugger/ADFA-7296 (#2311 at dd7ee1953) into ADFA-7304
davidschachterADFA Dec 1, 2026
559fb19
ADFA-7304 execute: a commit that SQLite rolled back says so at finali…
davidschachterADFA Dec 1, 2026
f4c3722
ADFA-7379 SQLite debugger: an 80-byte event record with an execution_…
davidschachterADFA Dec 1, 2026
6750d46
ADFA-7379 SQLite debugger: an execution id on STATEMENT, ROW and PROF…
davidschachterADFA Dec 1, 2026
ec05501
ADFA-7379 SQLite debugger: keep the execution id across a SQLITE_SCHE…
davidschachterADFA Dec 1, 2026
b9a3129
style: spotless reformat, no functional change
davidschachterADFA Dec 1, 2026
f0e8d51
Merge sqlite-debugger/ADFA-7296 (#2311 at b9a31297e, ADFA-7379) into …
davidschachterADFA Dec 1, 2026
8760dc0
ADFA-7379 get_events: every event carries execution_id
davidschachterADFA Dec 1, 2026
69dd43b
Merge sqlite-debugger/ADFA-7297 (#2319 at 8760dc0f7: #2311's ADFA-737…
davidschachterADFA Dec 1, 2026
90c6286
ADFA-7379 SQLite debugger: a trigger step is not a nested statement
davidschachterADFA Dec 2, 2026
8a60b2b
ADFA-7296 SQLite debugger: changes only from a DML statement's own count
davidschachterADFA Dec 2, 2026
9c4d0fe
ADFA-7379 SQLite debugger: correct the eviction, version, cost and ro…
davidschachterADFA Dec 2, 2026
22009aa
ADFA-7296 SQLite debugger: the UTF-16 row-size cost is an accepted limit
davidschachterADFA Dec 2, 2026
bc41ff2
ADFA-7296 SQLite debugger: fix the WITH ... INSERT changes test
davidschachterADFA Dec 2, 2026
4ffc26d
ADFA-7296 SQLite debugger: refuse a cut number or null, keep the fake…
davidschachterADFA Dec 2, 2026
954de4a
ADFA-7379 get_events: the null cases in full; the JNI test names its …
davidschachterADFA Dec 2, 2026
6958e2f
Merge p21/ADFA-7296 (#2311 at 4ffc26dc0, ADFA-7379 review fixes) into…
davidschachterADFA Dec 2, 2026
6b745ce
Merge p22/ADFA-7297 (#2319 at 6958e2f90: #2311's ADFA-7379 review fix…
davidschachterADFA Dec 2, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 29 additions & 5 deletions subprojects/sqlite-debugger/README.md

Large diffs are not rendered by default.

302 changes: 289 additions & 13 deletions subprojects/sqlite-debugger/src/main/cpp/sqlitedbg.c

Large diffs are not rendered by default.

90 changes: 81 additions & 9 deletions subprojects/sqlite-debugger/src/main/cpp/sqlitedbg.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ extern "C" {
#endif

// The interface version. Raise it when anything below changes shape.
#define SQLITEDBG_INTERFACE_VERSION 2
// 4: the event record has execution_id (72 to 80 bytes).
#define SQLITEDBG_INTERFACE_VERSION 4

// sqlite3_auto_extension's type. On a device the JNI layer looks it up in libsqlite3x.so with
// dlsym (requery exports every sqlite3_ function); host tests pass SQLite's own.
Expand Down Expand Up @@ -85,31 +86,84 @@ enum {
SQLITEDBG_EVENT_PROFILE = 2,
// The app asked SQLite to close the connection (SQLITE_TRACE_CLOSE); sql is empty.
SQLITEDBG_EVENT_CLOSE = 3,
// A statement returned a row (SQLITE_TRACE_ROW). Recorded only while a client is connected and
// row recording is on (sqlitedbg_set_row_capture); the data is the row's values, in the row
// layout below, not SQL. rows is the row's number in its statement, from 1.
SQLITEDBG_EVENT_ROW = 4,
};

enum {
// sql was cut at max_sql_bytes.
// The data was cut: SQL at max_sql_bytes, or a row's values at the row limits.
SQLITEDBG_EVENT_TRUNCATED = 1u << 0,
// sql has its bound values written in (sqlite3_expanded_sql). Only while a client is
// connected (sqlitedbg_set_client_connected): expanding a 1 MB value costs 2 MB on every run.
SQLITEDBG_EVENT_EXPANDED = 1u << 1,
// SQLITEDBG_EVENT_PROFILE only: rows were left unrecorded while row recording was on, because the
// statement returned more than the per-statement limit, or because the producer could not record
// a row (the byte budget is below a row header, or an allocation failed).
SQLITEDBG_EVENT_ROWS_CUT = 1u << 2,
};

// One event as sqlitedbg_read_events copies it out: this header, then sql_bytes of UTF-8 (no
// terminating NUL), then zero padding to a multiple of 8 bytes. Fields are in the CPU's byte order
// One event as sqlitedbg_read_events copies it out: this header, then data_bytes of data, then zero
// padding to a multiple of 8 bytes. The data is UTF-8 SQL (no terminating NUL) for every kind but
// SQLITEDBG_EVENT_ROW, whose data is its values (below). Fields are in the CPU's byte order
// (little-endian on every ABI we build). The JNI layer hands the bytes to Kotlin unchanged, so
// EventDecoder.kt mirrors this layout; change both together.
typedef struct sqlitedbg_event_record {
uint32_t record_bytes; // the whole record, padding included
uint32_t kind; // SQLITEDBG_EVENT_STATEMENT, _PROFILE or _CLOSE
uint32_t kind; // SQLITEDBG_EVENT_STATEMENT, _PROFILE, _CLOSE or _ROW
uint64_t seq; // 1, 2, 3...: every event made, dropped or not, gets the next one
uint64_t connection_id; // sqlitedbg_connection.id
int64_t thread_id; // gettid() of the thread running the statement
int64_t time_ns; // CLOCK_REALTIME when the event happened
int64_t duration_ns; // SQLITEDBG_EVENT_PROFILE only; -1 for the others
uint32_t flags; // SQLITEDBG_EVENT_TRUNCATED, SQLITEDBG_EVENT_EXPANDED
uint32_t sql_bytes;
} sqlitedbg_event_record; // 56 bytes; the SQL text follows
uint32_t flags; // SQLITEDBG_EVENT_TRUNCATED, _EXPANDED, _ROWS_CUT
uint32_t data_bytes;
// SQLITEDBG_EVENT_PROFILE: the rows the statement returned, whether or not they were recorded.
// SQLITEDBG_EVENT_ROW: this row's number, from 1. -1 otherwise, and -1 for a statement the
// extension did not see start (SQLite's own nested statements, or more than
// SQLITEDBG_STATEMENT_SLOTS statements stepped in turn on one connection).
int64_t rows;
// SQLITEDBG_EVENT_PROFILE of a statement that may write (sqlite3_stmt_readonly false): the rows
// it changed itself, as sqlite3_changes64 counts them (not those changed by triggers or foreign
// key actions); 0 when it changed none, as a CREATE TABLE. -1 (unknown) for a read-only
// statement, for the other kinds, when rows is -1, and when the statement had not finished when
// the event fired (reset or finalized part way, as an INSERT ... RETURNING stepped once, or a step
// that returned SQLITE_BUSY): its count is then partial or not yet set. Also -1 when the
// connection's total changed while the statement ran and it is not an INSERT, UPDATE, DELETE or
// REPLACE (a leading WITH counts), as a PRAGMA stepped across another statement's INSERT: the
// count sqlite3_changes64 holds is then that statement's.
int64_t changes;
// The run of a statement this event belongs to: the seq of its STATEMENT record, on that record
// and on the PROFILE and ROW records of the run. 0: none or unknown (a trigger's STATEMENT, a
// statement nested in a callback, an EXPLAIN, a CLOSE, or a statement the extension did not see
// start). A statement evicted from its slot keeps its id on its STATEMENT and on the ROW events
// recorded before the eviction; its later rows are not recorded, and its PROFILE has 0. Not contiguous,
// and restarting with the process like seq.
uint64_t execution_id;
} sqlitedbg_event_record; // 80 bytes; the data follows

// How many statements per connection the extension follows at once, to number their rows and count
// their changes. A connection that steps more statements in turn than this loses the oldest:
// its rows are not recorded and its PROFILE event has rows and changes -1.
#define SQLITEDBG_STATEMENT_SLOTS 16

// The data of an SQLITEDBG_EVENT_ROW: this header, then `kept` values, each a sqlitedbg_row_value
// followed by stored_bytes of value. Nothing is aligned: read each field with memcpy.
typedef struct sqlitedbg_row_header {
uint32_t columns; // sqlite3_column_count of the statement
uint32_t kept; // values that follow; fewer than columns when the row limit was reached
} sqlitedbg_row_header; // 8 bytes

typedef struct sqlitedbg_row_value {
uint8_t type; // SQLITE_INTEGER, SQLITE_FLOAT, SQLITE_TEXT, SQLITE_BLOB or SQLITE_NULL
uint8_t cut; // 1 if fewer than full_bytes were stored
uint16_t reserved; // 0
uint32_t stored_bytes; // bytes that follow: 8 for INTEGER (int64) and FLOAT (IEEE double),
// 0 for NULL, UTF-8 for TEXT (cut at a character boundary), BLOB bytes
uint32_t full_bytes; // the value's whole size (sqlite3_column_bytes for TEXT and BLOB)
// A value over 1 MiB that does not fit the limits is not read: stored_bytes 0, cut 1.
} sqlitedbg_row_value; // 12 bytes

typedef struct sqlitedbg_read_result {
// The seq of the last event copied out, or if none was, `after` moved past any dropped events
Expand Down Expand Up @@ -137,9 +191,27 @@ typedef struct sqlitedbg_read_result {
void sqlitedbg_read_events(uint64_t after, void *out, size_t out_bytes, sqlitedbg_read_result *result);

// Whether a client is connected. While it is, statements are recorded with their bound values
// written in. Off at install.
// written in, and rows if row recording is on. Off at install.
void sqlitedbg_set_client_connected(int connected);

// Turns row recording on (max_rows_per_statement > 0) or off (0, as at install). While it is on and
// a client is connected, the first max_rows_per_statement rows of each statement become
// SQLITEDBG_EVENT_ROW events. TEXT and BLOB values longer than max_value_bytes are cut (0: 256), and
// a row's data stops at max_row_bytes (0: 4 KiB; at most SQLITEDBG_MAX_ROW_BYTES; never more than
// half the buffer less one header).
// Each value is read with the accessor of its own type (sqlite3_column_type first), so the app sees
// the same values and types afterwards: sqlite3_column_text converts a value in place, and on a BLOB
// it makes the app's own sqlite3_column_type return SQLITE_TEXT (SQLite 3.49.1, sqlitedbg_test.c). Rows of statements the extension did
// not see start are never recorded: that drops the rows of SQLite's own nested statements, such as
// the schema read a CREATE TABLE runs. PROFILE events count rows whether or not this is on.
void sqlitedbg_set_row_capture(uint32_t max_rows_per_statement, uint32_t max_value_bytes,
uint32_t max_row_bytes);

// The largest max_row_bytes that sqlitedbg_set_row_capture keeps; a larger one is lowered to it.
// sqlitedbg_read_events stops at the first record that does not fit its buffer, so a row record must
// stay well below the 256 KiB the server reads at a time (DatabaseTools.EVENT_BATCH_BYTES).
#define SQLITEDBG_MAX_ROW_BYTES (64u * 1024u)

// Server connections

#define SQLITEDBG_SERVER_BUSY_MS 3000
Expand Down
Loading
Loading