Repository navigation
Bind parameters in query (Rust core, Python SDK) - #1576
Merged
Merged
Conversation
The query_with methods and the Python params argument exist but ignore their params, so every new test fails on the unbound placeholders.
A sequence fills ? placeholders and a mapping fills :name placeholders, through SQLite's own binding, on every query path in the core and in the Python SDK.
thekevinscott
marked this pull request as ready for review
November 4, 2026 16:41
This was referenced Nov 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #1575 (Rust core + Python SDK; the TypeScript binding follows in a second PR from fresh
mainonce this merges).query(sql, params)handsparamsto SQLite's own parameter binding; values never enter the SQL text. A sequence fills?placeholders in order; a mapping fills:name(also@name/$name) placeholders, keyed without the prefix. Works for path-tables and declared tables.await db.query(sql, params=None). AcceptsNone,int,bool,float,str,bytes,bytearray. Any other value type raisesTypeError(unsupported parameter type: <type>), and an out-of-rangeintraisesOverflowError. Aparamsthat is neither a sequence nor a mapping (astrincluded) raisesTypeError.Params::{Positional(Vec<Value>), Named(HashMap<String, Value>)}. New methods:DirSQL::query_with,query_ordered_with,query_each_withandAsyncDirSQL::query_with. The existing methods bindParams::default()(empty).DbError::Params, which Python raises asRuntimeError): a wrong count, a missing name, an unused mapping key, or a sequence/mapping that does not match the placeholder style each fail with a message naming the problem.run_statement(both runs of a batched function) andquery_each_ref(the streaming path, including its batched fallback).Parity: this introduces drift, because TypeScript lacks params until the follow-up PR. That PR is tracked by #1575, which stays open.
PARITY.mdis updated.Manual run: built with
maturin develop --releaseand wrote three JSON files whoseadviceholdsit's "quoted" — ok,ünïcødé ✓ 日本語andx'; DROP TABLE t; --. Then ranawait db.query("SELECT path FROM './*.json' WHERE content ->> 'advice' = :advice", {"advice": text})for each. Each returned exactly its own file (a.json,b.json,c.json), and a non-matching value returned[]. The error cases printedRuntimeError the query has 1 parameter(s), but 2 value(s) were given,RuntimeError the named parameter :a has no valueandTypeError unsupported parameter type: object.E2E Verification
packages/python/e2e-attestations/<branch>.jsonreceipt written ifpackages/pythonchanged (just e2e-attest-python)packages/ts/e2e-attestations/<branch>.jsonreceipt written ifpackages/tschanged (just e2e-attest-ts)cargo test -p dirsql --features clicd packages/python && testing-conventions e2e attest 'uv run python -m pytest tests/e2e/query_contract_test.py tests/e2e/on_file_query_test.py tests/e2e/declared_table_name_test.py tests/e2e/use_case_join_test.py tests/e2e/stat_speed_test.py -x -q'cd packages/ts && testing-conventions e2e attest 'pnpm exec vitest run --dir tests/e2e query-contract declared-table-name'Changelog / Migrations
<root>/<pkg>/changelog.d/for each changed package (or:skip-changelogtrailer on a commit with reason)<root>/<pkg>/migrations.d/for each changed package (every subsection but Summary_None._when nothing breaks)