Skip to content

mssql: report unsupported constructs and dropped placeholders - #6

Open
EliSauder wants to merge 8 commits into
mainfrom
mssql/unsupported-constructs
Open

EliSauder wants to merge 8 commits into
mainfrom
mssql/unsupported-constructs

Conversation

@EliSauder

@EliSauder EliSauder commented Nov 13, 2026 •

Copy link
Copy Markdown
Owner

Things sqlc silently got wrong, or panicked on, for SQL Server now either work or fail with a clear error.

  • Named MERGE/EXEC queries (also in block comments) are reported instead of dropped.
  • A safety net reports any @name a named query has that did not become a parameter.
  • Placeholders kept: TOP (@n) PERCENT, CONVERT's style.
  • :copyfrom no longer panics; built-in Go generation rejects :execlastid for its go-mssqldb binding, whose LastInsertId always errors. External generators are not restricted.

Commits

  • 9f1f67aba fix(mssql): report a named query sqlc cannot analyze
  • 0f527029a fix(mssql): report an unsupported query named in a block comment
  • 982cee5ae fix(mssql): keep the placeholder in TOP (@n) PERCENT
  • deffbd571 fix(validate): allow an INSERT whose VALUES has no FROM list
  • 4c03a9a89 fix(golang): reject :execlastid for SQL Server
  • aef45f655 fix(mssql): report a placeholder the converter drops
  • 3908e041d fix(mssql): keep the placeholder in CONVERT's style
  • 41ae5fab4 refactor(mssql): supply driver execution capabilities to Go generation

Driver capability inversion

The SQL Server engine owns the go-mssqldb restriction and diagnostic behind an optional, generic execution-capability provider. Compiler results carry the provider; the built-in Go assembly supplies the selected SQL package and driver and injects its capabilities into Go generation. Go codegen no longer chooses this restriction by engine name.

Engines without a provider retain their existing behavior. Other driver bindings do not inherit the go-mssqldb restriction, and external process/WASM generators receive unchanged plugin requests. No plugin protocol or serialized configuration changes are required.

End-to-end coverage preserves the existing explicit database/sql diagnostic, adds the default SQL-package case, and verifies a SQL Server :execlastid query reaches an external generator successfully. The complete base replay corpus, focused last-ID cases across engines, touched-package tests with the race detector, targeted go vet, and CLI build pass.

Test changes for independence

  • TOP PERCENT's query has its own case, analyze_top_percent, rather than the core PR's analyze_paging.

Independence. This is one of five PRs split from #1, each off main with no dependency on the others: it builds, passes the base suite and keeps the core context at or above main's, alone. Its goldens are generated on this branch, and they hold unchanged with all five merged, whose code then equals the original branch. Parallel PRs add lines next to each other in convert.go, functions.jsonl and the dialect settings, so whichever merges later may need a rebase that keeps both sides.

Verification. Behavior was checked against SQL Server 2025 in #1 (goldeneye or sp_describe_*). go test ./internal/endtoend -run TestReplay/base/ and the touched packages' tests pass; generated Go goldens pass go vet.

EliSauder and others added 7 commits November 12, 2026 18:50
A statement the converter does not handle, such as MERGE or EXEC, was
skipped, so a query named on one silently went missing from the
generated code. Skipping is right for a schema, which holds statements
sqlc has no use for, but a statement carrying a query name is now
reported as unsupported, at the statement.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
A named query on a statement sqlc cannot analyze is reported rather than
dropped, but the check only recognized a -- name: comment, so a MERGE
named with /* name: Foo :exec */, which sqlc also reads, was still
dropped silently. Both comment styles are now recognized.

Addresses review comment r4557025570 on #1.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
TOP n PERCENT was skipped as no row count, which dropped a placeholder
in it from the query's parameters, so the generated code did not pass
it and the query failed with an undeclared variable. The percentage is
now analyzed as the float SQL Server takes it as.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Checking a :copyfrom query read the FROM list of its INSERT ... VALUES
without checking it was there. PostgreSQL's converter gives VALUES an
empty one, but SQL Server's leaves it nil, so any :copyfrom query on SQL
Server panicked. It now reaches the generator, which reports that
:copyfrom is not supported for the driver.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
go-mssqldb never reports a last insert ID: its LastInsertId always
returns an error, so the code generated for an :execlastid query failed
every time it ran. Generating one is now an error that points at the
OUTPUT INSERTED clause SQL Server returns the ID with.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
A placeholder in a construct the converter does not follow, as
TABLESAMPLE (@n PERCENT) or CONVERT's style, was dropped from the
query's parameters, generating code that passed the query too few
arguments. Every @name in a named query's text, outside strings,
quoted names and comments, must now be one of its parameters, and one
that is not is reported where it is.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
A style given as a placeholder, as CONVERT(nvarchar(30), at, @Style),
was dropped. It is now passed as an int, through a function returning
the converted value, which may then be NULL; a literal style is left
as it was.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Comment thread internal/codegen/golang/gen.go Resolved
Expose optional engine-owned driver capabilities through compiler results. Apply LastInsertId restrictions only to built-in Go generation, preserving other engines and external generators.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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