Repository navigation
fix(coreanalyzer): Infer parameter names in LIMIT ? OFFSET ? clauses for SQLite and MySQL - #4731
Open
manuelschoene wants to merge 2 commits into
Open
manuelschoene wants to merge 2 commits into
manuelschoene wants to merge 2 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Under the core analyzer (
SQLCEXPERIMENT=coreanalyzer),LIMITandOFFSETplaceholders were generated asColumn1/Column2instead ofLimit/Offset. The legacy compiler names them inresolve.go; the bridge into the analysis core had no equivalent, and the core leaves them unnamed because the database reports no name for them.Fixes #4730.
Fix
limitParamNamesininternal/compiler/parse_core.gofinds the placeholders that are a wholeLimitCountorLimitOffsetof aSELECT,UPDATEorDELETEand names themlimitandoffset.LIMIT x, yasLIMIT y OFFSET x, so the comma form getsOffset,Limitin the right order.compiler.Parameter.InferredNamerather than onto the parameter's column, andpluginQueryParamapplies it only when the column has no name. The name therefore only reaches codegen:sqlc analyzekeeps printing what the analysis reports ("name": ""), which theanalyze_*cases and goldeneye check against the database. Writing it onto the column changedanalyze_expressions/{sqlite,clickhouse}andanalyze_percent_offset/duckdb; core: carry enums, views and missing placeholders through the analysis core #4614 ran into the same thing when it tried naming them in the core.sqlc.arg()/@namein aLIMITstill wins over the inferred name.Tests
New case
select_limit_comma/sqlitecovers the comma form, where the first placeholder is the offset, so a fix that names placeholders by position would swap the two.TestReplay/base: all green, no golden changed.SQLC_TEST_CORE=1 TestReplay/core: 294 → 290 failing cases, none regressed. Fixed:select_limit_comma/sqlite,select_limit/sqlite,select_limit/mysql,limit/sqlite.limit/mysqlstill fails in the core context: the core reports no parameter at all forUPDATE/DELETE ... LIMIT ?on MySQL, which core: carry enums, views and missing placeholders through the analysis core #4614 addresses.limitParamNamesalready coversUPDATEandDELETE, so that case should be named once core: carry enums, views and missing placeholders through the analysis core #4614 lands.golangci-lintshows no new issues.