Skip to content

fix(sqlite): correct parameter binding when mixing sqlc.arg() with bare "?" - #1

Open
abgoyal wants to merge 1 commit into
mainfrom
fix/sqlite-mixed-param-binding
Open

fix(sqlite): correct parameter binding when mixing sqlc.arg() with bare "?"#1
abgoyal wants to merge 1 commit into
mainfrom
fix/sqlite-mixed-param-binding

Conversation

@abgoyal

@abgoyal abgoyal commented Jun 7, 2026

Copy link
Copy Markdown
Owner

When a SQLite query uses both sqlc.arg() named parameters and bare ? placeholders, the generated SQL has numbered ?N for named params but leaves bare ? unnumbered. SQLite's auto-numbering for bare ? then conflicts with the explicit ?N values, silently binding arguments to wrong columns.

Fix by numbering all placeholders sequentially in text order when the mixed case is detected, ensuring positional argument passing matches the generated ?N values.

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request adds support for mixing named parameters (via sqlc.arg()) and bare ? placeholders in SQLite queries by numbering all placeholders in text order when both coexist. The review feedback identifies two critical issues in internal/sql/rewrite/parameters.go: first, using len(numbs) > 0 to detect bare placeholders is imprecise and can lead to parameter conflicts; second, isBareParamRef incorrectly matches explicitly numbered parameters, which would corrupt them during rewriting. Actionable code suggestions are provided to resolve both issues.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread internal/sql/rewrite/parameters.go
Comment thread internal/sql/rewrite/parameters.go
…re ?

When a SQLite query uses both sqlc.arg() named parameters and bare ?
placeholders, the generated SQL has numbered ?N for named params but
leaves bare ? unnumbered. SQLite's auto-numbering for bare ? then
conflicts with the explicit ?N values, silently binding arguments to
wrong columns.

Fix by numbering all placeholders sequentially in text order when the
mixed case is detected, ensuring positional argument passing matches
the generated ?N values.
@abgoyal
abgoyal force-pushed the fix/sqlite-mixed-param-binding branch from b6da94b to 7445b49 Compare June 7, 2026 06:54
@abgoyal abgoyal changed the title fix(sqlite): correct parameter binding when mixing sqlc.arg() with ba… fix(sqlite): correct parameter binding when mixing sqlc.arg() with bare ? Jun 7, 2026
@abgoyal abgoyal changed the title fix(sqlite): correct parameter binding when mixing sqlc.arg() with bare ? fix(sqlite): correct parameter binding when mixing sqlc.arg() with bare "?" Jun 7, 2026
@abgoyal

abgoyal commented Jun 7, 2026

Copy link
Copy Markdown
Owner Author

/gemini-review

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