Repository navigation
fix(sqlite): Convert ORDER BY and LIMIT ... OFFSET clauses in DELETE/UPDATE statements into shared AST nodes - #4707
Open
manuelschoene wants to merge 3 commits into
Conversation
The CI uses a SQLite database built without the SQLITE_ENABLE_UPDATE_DELETE_LIMIT option enabled. Therefore, the syntax is not recognized and is expected to fail.
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.
SQLite accepts
ORDER BYandLIMIT ... OFFSETonUPDATEandDELETE(withSQLITE_ENABLE_UPDATE_DELETE_LIMIT), and sqlc parses that syntax on purpose. The meyer parser fillsOrderByandLimit.OffsetonDeleteStmt/UpdateStmt, but the conversion into sqlc's AST kept onlyLimit.Count. Any parameter in theORDER BYorOFFSETwas therefore missing from the generated method, which then failed at runtime with too few arguments. On the core analyzer path theLIMITparameter was dropped as well.Fixes #4706.
Changes
ast.DeleteStmtandast.UpdateStmtgainSortClauseandLimitOffset(same names as onSelectStmt), andFormatprintsORDER BY ... LIMIT ... OFFSET ....WalkandApplyvisit the new fields.Applydid not visitLimitCounton these two statements before; it does now.limitCountis replaced byconvertOrderLimit, which convertsOrderBy,Limit.CountandLimit.Offset.find_params.gotracksLimitOffsetonDELETE/UPDATE, so the parameter is namedOffsetas it is forSELECT.analyzeUpdate/analyzeDeletenow type the sort clause and the limit/offset (typeOrderLimit).Tests
New end-to-end case
internal/endtoend/testdata/update_delete_order_by_limit/sqlitewith four queries:DELETEandUPDATE, each once withLIMIT ? OFFSET ?and once with a parameter inORDER BY. Its golden file was written before the fix, by hand, with the names and types sqlc generates for the equivalentSELECT. It failed before the fix and passes after it without changes.TestReplay,TestFormatandTestJsonSchemapass. Database-backed tests were not run locally.SQLC_TEST_CORE=1): the parameters are now bound, butLIMIT/OFFSETparameters are namedColumn3/Column4there, so the new case fails in that context. PlainSELECT ... LIMIT ? OFFSET ?has the same naming on the core path (limit/sqliteandselect_limit/sqlitealready fail there onmain). The set of failing core cases is identical before and after this change.Not in this PR
UpdateStmt/DeleteStmtFormatstill printsRETURNINGafterLIMIT, while SQLite expects it beforeORDER BY/LIMIT. This predates the change.ORDER BY ... LIMITonUPDATE/DELETE. The dolphin converter only setsLimitCountand could use the new fields. Not the topic of this PR.