Skip to content

Fix Postgres placeholder rewrite to preserve sqlc numbered placeholders - #18

Open
DeveloperDurp wants to merge 1 commit into
mainfrom
codex/fix-postgresql-placeholder-rewrite-issue
Open

Fix Postgres placeholder rewrite to preserve sqlc numbered placeholders#18
DeveloperDurp wants to merge 1 commit into
mainfrom
codex/fix-postgresql-placeholder-rewrite-issue

Conversation

@DeveloperDurp

Copy link
Copy Markdown
Owner

Motivation

  • The PostgreSQL driver rewrite mangled sqlc/SQLite numbered placeholders (e.g. ?1 -> $11) causing prepared statements to refer to non-existent parameters and producing runtime query errors.

Description

  • Updated internal/pgdriver/rewrite.go so the placeholder rewriter consumes digits after ? and preserves numbered placeholders (e.g. ?1 -> $1) while still renumbering anonymous ? placeholders to $1, $2, ....
  • The rewriter now advances its internal counter to the highest explicit numbered index seen so that subsequent anonymous placeholders continue at the correct numbering.
  • Kept existing literal handling so ? occurrences inside single- or double-quoted strings remain untouched.
  • Added regression tests in internal/pgdriver/rewrite_test.go covering repeated numbered placeholders, mixed numbered/anonymous placeholders, and numbered placeholders inside string literals.

Testing

  • Ran go test -count=1 ./internal/pgdriver and the package tests passed successfully.
  • Ran gofmt checks and git diff --check to ensure formatting and basic checks passed with no reported issues.
  • Ran go test -count=1 ./..., which exercised many packages successfully but failed to complete because generated templ files and static/swagger-ui assets required by the top-level build/tests were not present in this checkout; this is a known repository precondition and unrelated to the placeholder fix.

Codex Task

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant