Skip to content

bridge: bind positional exec params by number - #5

Merged
sputn1ck merged 1 commit into
lightninglabs:mainfrom
jamaljsr:fix/exec-positional-param-bind
Jun 27, 2026
Merged

sputn1ck merged 1 commit into
lightninglabs:mainfrom
jamaljsr:fix/exec-positional-param-bind

Conversation

@jamaljsr

Copy link
Copy Markdown
Member

Fixes #4.

runExec sent positional-array params to db.exec({ bind: [...] }), which binds the array by SQLite slot order (order of first appearance) rather than by the $N number. Statements whose $N appear out of textual order — e.g. UPDATE … SET col = $3 WHERE k = $1 — therefore bound the WHERE key against the wrong value and silently matched zero rows, with no error.

runQuery already routes positional arrays through normalizePositionalParams, which remaps each $N to its slot by number. This change applies the same remap on the exec path: any non-empty params (array or object) now go through bindParams, leaving only the empty-params case on db.exec. So numbered parameters are now honored consistently across Query and Exec.

Test

Adds TestBrowserExecNumberedParamsOutOfOrderE2E, which exercises the exec path with out-of-order numbered params (UPDATE … SET v=$2 WHERE id=$1). It fails against the old worker (0 rows updated) and passes with this change. The existing UPDATE … RETURNING test only covered the query path, which is why this slipped through.

Changes

  • bridge/sqlite-worker.js (+12/-4) — route non-empty exec params through bindParams.
  • driver_browser_js_wasm_test.go (+80) — exec-path regression test.

runExec sent positional-array params to db.exec({ bind: [...] }), which
binds the array by SQLite slot order (order of first appearance) rather
than by the $N number. Statements whose $N appear out of textual order --
e.g. UPDATE ... SET col = $3 WHERE k = $1 -- therefore bound the WHERE
key against the wrong value and silently matched zero rows.

runQuery already routes positional arrays through normalizePositionalParams
(added in "Fix numbered SQLite parameter binding"), which remaps each $N to
its slot by number. This applies the same remap on the exec path by sending
any non-empty params (array or object) through bindParams, leaving only the
empty-params case on db.exec.

Adds TestBrowserExecNumberedParamsOutOfOrderE2E covering the exec path; it
fails (0 rows updated) against the old worker and passes with this change.
The existing UPDATE...RETURNING test only exercised the query path.
@sputn1ck
sputn1ck merged commit 0dce68f into lightninglabs:main Jun 27, 2026
4 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.

Exec binds numbered ($N) positional parameters by appearance order, not by number (Query path is correct)

2 participants