Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix SQLite Engine Comparison Operators and ORDER BY Parsing#4126

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
mgilbir wants to merge3 commits intosqlc-dev:main
base:main
Choose a base branch
Loading
frommgilbir:fix-sqlite-parsing-comparison-and-order

Conversation

@mgilbir
Copy link

@mgilbirmgilbir commentedOct 6, 2025
edited
Loading

Summary

This PR fixes critical parsing issues in the SQLite engine where comparison operators were incorrectly defaulting to= and ORDER BY clauses were generating incorrect AST nodes. It also restores correct handling ofEXISTS/NOT EXISTS so SQLite queries emit the right boolean expressions and generated code.

Issues Fixed

  1. Comparison operators not parsed correctly - All comparison expressions were defaulting to= operator instead of extracting the actual operator (<,>,<=,>=,!=,<>,IS,LIKE,GLOB,MATCH,REGEXP)
  2. NOT operator variants not supported -NOT LIKE,NOT GLOB,NOT IN,IS NOT NULL, etc. were not handled properly
  3. ORDER BY generates wrong AST nodes - ORDER BY clauses were incorrectly creatingCaseExpr nodes instead of properSortBy nodes
  4. Missing ORDER BY integration - SELECT statements weren't properly setting theSortClause field
  5. NOT EXISTS flattened incorrectly - SQLite treatedNOT EXISTS as a bare subquery, producingexists variables instead of the expectednot_exists boolean output

Changes Made

Core Fixes (internal/engine/sqlite/convert.go)

  • EnhancedconvertComparison: Now properly extracts actual comparison operators instead of defaulting to=
  • AddedextractComparisonOperator: Comprehensive function handling all SQLite comparison operators including NOT variants
  • FixedconvertOrderby_stmtContext: Now generates properSortBy AST nodes with correct direction (ASC/DESC) and null handling (NULLS FIRST/LAST)
  • EnhancedconvertMultiSelect_stmtContext: Added ORDER BY integration to properly setSortClause
  • AddedconvertNullComparison: HandleIS NULL/IS NOT NULL expressions
  • ExtendedconvertUnaryExpr: Detects unaryNOT via the unary-operator node, including wrappingNOT EXISTS as aBoolExpr
  • HardenedconvertInSelectNode: RecognisesNOT EXISTS when the context begins with the NOT token so the AST preserves the negation

New Test Coverage (internal/engine/sqlite/convert_test.go)

  • 35 comprehensive test cases covering all fixed functionality
  • Comparison operator tests: All SQLite operators (<,>,<=,>=,=,!=,<>,<<,>>,&,|,IS,LIKE,GLOB,MATCH,REGEXP)
  • NOT variant tests:NOT LIKE,NOT GLOB,NOT IN,IS NOT NULL, etc.
  • ORDER BY tests: Direction handling, null ordering, multiple columns
  • Complex query tests: Real-world scenarios with multiple operators and clauses

Operators Now Supported

  • Comparison:<,>,<=,>=,=,!=,<>
  • Bitwise:<<,>>,&,|
  • Pattern matching:LIKE,GLOB,MATCH,REGEXP
  • Null testing:IS NULL,IS NOT NULL
  • List membership:IN,NOT IN
  • All NOT variants:NOT LIKE,NOT GLOB,NOT MATCH,NOT REGEXP

Testing

# All new tests passgotest -v ./internal/engine/sqlite -run TestConvert# Existing functionality preservedgotest ./internal/engine/sqlite# Regression coverage for managed DB fixturesgotest ./internal/endtoend -run'TestReplay/managed-db/select_exists/sqlite'gotest ./internal/endtoend -run'TestReplay/managed-db/select_not_exists/sqlite'

Example Impact

Before (incorrect):

SELECT*FROM usersWHERE age>=18ORDER BY nameDESC-- Generated AST: A_Expr with "=" operator, CaseExpr for ordering

After (correct):

SELECT*FROM usersWHERE age>=18ORDER BY nameDESC-- Generated AST: A_Expr with ">=" operator, SortBy with DESC direction

Breaking Changes

  • SQLiteEXISTS/NOT EXISTS return types: Generated Go methods now returnbool (and emit variables namedexists/not_exists) instead of the previousint64 placeholder. Projects that already consume these helpers must update their call sites to expect a boolean result.
  • Parameter propagation forNOT EXISTS: Because the AST now retains the inner select, generated methods once again surface the query arguments. Call sites that relied on the buggy zero-argument signature will need to pass the correct inputs (for example,id inBarNotExists).

Related Issues

Fixes parsing issues with SQLite comparison operators and ORDER BY clauses that could lead to incorrect SQL generation and runtime errors.

@dosubotdosubotbot added size:XLThis PR changes 500-999 lines, ignoring generated files. 🔧 golang labelsOct 6, 2025
@mgilbirmgilbir marked this pull request as draftOctober 6, 2025 01:03
@anthonyg876
Copy link

Hey@mgilbir, I am guessing that this PR will fix:#4188, yes?

@mgilbir
Copy link
Author

Hey@mgilbir, I am guessing that this PR will fix:#4188, yes?

Yes, I left a description on how to reproduce it with your schema in the linked issue.

anthonyg876 reacted with heart emoji

@anthonyg876
Copy link

@kyleconroy Hey Kyle, wanted to ask what the PR review process is like? I wanted to see if there is anything that can be done to get eyes on this ticket to possibly be merged into the next version drop?

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

size:XLThis PR changes 500-999 lines, ignoring generated files.🔧 golang

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@mgilbir@anthonyg876

[8]ページ先頭

©2009-2025 Movatter.jp