Skip to content

fix(sqlite): convert bound parameters with --bind and bindings - #348

Merged
kvlonge merged 3 commits into
mainfrom
fix/sqlite-convert-bindings
Nov 30, 2026
Merged

kvlonge merged 3 commits into
mainfrom
fix/sqlite-convert-bindings

Conversation

@kvlonge

@kvlonge kvlonge commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

Why

sqlbabel convert --dialect sqlite refused every statement with a parameter marker (?, ?N, :name, @name, $name), because nothing could bind values to it. The converter already types a bound parameter by its value's storage class for the evidence replay; the command line and Python had no way to pass values.

Changes

  • convert --bind MARKER=LITERAL (repeatable) and ConvertOptions.bindings in Python. Each marker becomes its value's typed DuckDB literal (CAST(7 AS BIGINT), CAST('x' AS VARCHAR), real and blob literals, NULL), so the output runs as it is, specialised to those values.
  • Works for one query and for scripts: each statement takes the bindings its markers name. A marker with no value, a value no statement names, and a value that is not exactly one SQLite literal (number with an optional sign, string, blob or NULL) are refused. --bind with another dialect exits 2.
  • With --bind, ?N binds only a ?/?N marker; a name binds by its name. A view naming a parameter is refused, as SQLite refuses it.
  • The verify path (PREPARE/EXECUTE with $n) is unchanged.
  • Docs: convert, Python API, architecture.

Verification

  • SQLite unit tests for binding, the literal-only rule and the script rules.
  • Python API tests compare convert(bindings=) with convert --bind and run a ? SELECT, a ?N INSERT then UPDATE … RETURNING and a :name INSERT … RETURNING on DuckDB against Python sqlite3's rows and types.
  • SQLite verify: 1,083 cases, 1,012 passed, 0 failed; the translation measure is unchanged.
  • make check-ci passes on the head.

Bound values are written in place of their markers as typed DuckDB
literals, so the output runs as it is, for one statement or a script.
Each value must be one SQLite literal; a marker with no value and a
value no statement names refuse.
@kvlonge
kvlonge enabled auto-merge November 30, 2026 14:11
@kvlonge
kvlonge added this pull request to the merge queue Nov 30, 2026
Merged via the queue into main with commit b1dbe70 Nov 30, 2026
15 checks passed
@kvlonge
kvlonge deleted the fix/sqlite-convert-bindings branch November 30, 2026 15:38
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