Fix recurring crash when Connection deinitializes - #1373
Open
vjymisal0 wants to merge 3 commits into
Open
Conversation
The `~=` operator overloads used for Range/ClosedRange/PartialRange
pattern matching (e.g. `0...26 ~= column`) build their SQL fragment
without wrapping it in parentheses, unlike every other comparison
operator (`>`, `<`, `==`, etc.), which all self-wrap via
`Operator.infix(...)`.
This is harmless standalone (e.g. inside `.filter(...)`), but it
produces invalid SQL when used as a column-level CHECK constraint via
`table.create { t in t.column(col, check: 0...26 ~= col) }`, because
Schema.swift's per-column `definition()` relies on the check
expression already being parenthesized (it just does
`"CHECK" + " " + check`, same as the table-level `check()` builder
relies on `.prefix` to add its own parens). Since BETWEEN/range
expressions weren't self-wrapped, the generated SQL came out as:
CREATE TABLE "t" ("type" INTEGER NOT NULL CHECK "type" BETWEEN 0 AND 26)
which SQLite rejects with a syntax error near the CHECK condition,
exactly as reported in stephencelis#1056.
Fixes stephencelis#1056.
Fix: wrap the `~=` operators' generated SQL in parens, matching the
convention already used by every other comparison operator. Updated
the existing BETWEEN/range operator tests to expect the parenthesized
output, and added a regression test in SchemaTests that reproduces the
exact column-level CHECK scenario from the issue and asserts the
generated CREATE TABLE statement is now well-formed.
Verified by tracing the SQL-generation code path end-to-end (Operator
`infix`/`wrap` helpers, the `~=` overloads, and Schema.swift's
`definition()`/`check()`) since a full Swift toolchain wasn't
available in this environment to run `swift test` directly; the
updated/added unit tests exercise this exact path and should be run
by CI.
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.
Fixes #1276
nnUse sqlite3_close_v2 from deinit so an out-of-scope Connection does not crash when statements are still outstanding. I could not run Swift tests in this environment because the Swift toolchain is unavailable.