Skip to content

fix(reader_base): bind TextQuery args correctly instead of passing dal.QueryArg itself - #177

Merged
trakhimenok merged 1 commit into
mainfrom
fix/textquery-args
Sep 9, 2026
Merged

fix(reader_base): bind TextQuery args correctly instead of passing dal.QueryArg itself#177
trakhimenok merged 1 commit into
mainfrom
fix/textquery-args

Conversation

@trakhimenok

Copy link
Copy Markdown
Contributor

Summary

  • dal.NewTextQuery accepts dal.QueryArg{Name, Value} values, but getReaderBase's dal.TextQuery branch passed each arg struct straight through as a[i] = argdatabase/sql has no idea how to convert a dal.QueryArg into a bind value, so any TextQuery with a non-empty Args() failed outright: sql: converting argument $1 type: unsupported type dal.QueryArg, a struct. Named @param/:param/$param placeholders in native SQL could never bind at all. Found via datatug-cli PR #206's body (item 2) — its pkg/secureread.RunNativeSQL currently works around this by binding placeholders itself before ever reaching this adapter.
  • Fix: a named arg (Name != "") becomes a sql.NamedArg via sql.Named, so an @name-style placeholder binds by name; a positional arg (Name == "") passes its Value straight through for ordinary ?/$N placeholders.

Checked for duplicate work first

Per instructions, checked whether the pushed layered-acl-query branch (codex layered-ACL work) already fixes this before doing anything:

git fetch origin layered-acl-query
git diff origin/main..origin/layered-acl-query -- reader_base.go

It only changes reader_base.go's dal.StructuredQuery branch (adds dialect-aware compileStructuredSQL for SQLite), leaving the dal.TextQuery branch — the one this bug lives in — completely untouched. No overlap, nothing duplicated; proceeded with the fix.

Reproduction

Three new tests, run against a real in-memory SQLite database (modernc.org/sqlite, not a mock, matching this repo's own openTestSQLiteDB helper) — positional-only, named-only, and mixed positional+named in the same query:

  • TestGetReaderBase_TextQuery_PositionalArgs
  • TestGetReaderBase_TextQuery_NamedArgs
  • TestGetReaderBase_TextQuery_MixedArgs

Confirmed all three fail with the exact error above against the unfixed code (go test -run TestGetReaderBase_TextQuery -v before the fix), then pass cleanly after the one-line fix.

Validation

  • wb run -- go build ./... — clean.
  • wb run -- go vet ./... — clean.
  • wb run -- go test ./... — clean, full suite green, including the three new tests.
  • wb run -- go test ./... -run TestConformance -v — the shared dalgotest.RunConformance suite (17 subtests) stays fully green.
  • gofmt -l . — clean, no output.

go mod tidy -diff reports a large, pre-existing go.sum cleanup (stale versions of dal-go/dalgo, dal-go/record, modernc.org/sqlite, etc. left over from past bumps) — unrelated to this fix and out of scope for a narrow bug fix, not touched here.

Do not merge — landing is owned by a separate session. (Note: dalgo repos auto-tag on main — no hand-tagging done or needed here.)

🤖 Generated with Claude Code

https://claude.ai/code/session_01Dd3aoE41JSShyUuUmW8sSi

…l.QueryArg itself

dal.NewTextQuery accepts dal.QueryArg{Name, Value} values, but
getReaderBase's TextQuery branch passed each arg struct straight
through as a[i] = arg — database/sql has no idea how to convert a
dal.QueryArg into a bind value, so any TextQuery with a non-empty
Args() failed outright ("sql: converting argument $1 type: unsupported
type dal.QueryArg, a struct"). Named @param/:param/$param placeholders
in native SQL could never bind at all; pkg/secureread.RunNativeSQL
(datatug-cli) currently works around this by binding placeholders
itself before ever reaching this adapter.

Fix: a named arg (Name != "") becomes a sql.NamedArg via sql.Named, so
an @name-style placeholder binds by name; a positional arg (Name == "")
passes its Value straight through for ordinary ?/$N placeholders.

Reproduced first with three new tests against a real in-memory SQLite
database (modernc.org/sqlite, not a mock) — positional-only,
named-only, and mixed — confirmed all three fail with the exact error
above against the unfixed code, then pass after the one-line fix.

Checked whether the pushed layered-acl-query branch already touched
this: it only changes reader_base.go's dal.StructuredQuery branch
(dialect-aware compilation), not the dal.TextQuery arg-binding branch
this fixes — no overlap, nothing duplicated.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Dd3aoE41JSShyUuUmW8sSi
@trakhimenok
trakhimenok merged commit 98b9d6f into main Sep 9, 2026
5 checks passed
@trakhimenok
trakhimenok deleted the fix/textquery-args branch September 9, 2026 13:01
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