Fix SQLite Engine Comparison Operators and ORDER BY Parsing #4126
+658
−16
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.
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 EXISTSso SQLite queries emit the right boolean expressions and generated code.Issues Fixed
=operator instead of extracting the actual operator (<,>,<=,>=,!=,<>,IS,LIKE,GLOB,MATCH,REGEXP)NOT LIKE,NOT GLOB,NOT IN,IS NOT NULL, etc. were not handled properlyCaseExprnodes instead of properSortBynodesSortClausefieldNOT EXISTSflattened incorrectly - SQLite treatedNOT EXISTSas a bare subquery, producingexistsvariables instead of the expectednot_existsboolean outputChanges Made
Core Fixes (
internal/engine/sqlite/convert.go)convertComparison: Now properly extracts actual comparison operators instead of defaulting to=extractComparisonOperator: Comprehensive function handling all SQLite comparison operators including NOT variantsconvertOrderby_stmtContext: Now generates properSortByAST nodes with correct direction (ASC/DESC) and null handling (NULLS FIRST/LAST)convertMultiSelect_stmtContext: Added ORDER BY integration to properly setSortClauseconvertNullComparison: HandleIS NULL/IS NOT NULLexpressionsconvertUnaryExpr: Detects unaryNOTvia the unary-operator node, including wrappingNOT EXISTSas aBoolExprconvertInSelectNode: RecognisesNOT EXISTSwhen the context begins with the NOT token so the AST preserves the negationNew Test Coverage (
internal/engine/sqlite/convert_test.go)<,>,<=,>=,=,!=,<>,<<,>>,&,|,IS,LIKE,GLOB,MATCH,REGEXP)NOT LIKE,NOT GLOB,NOT IN,IS NOT NULL, etc.Operators Now Supported
<,>,<=,>=,=,!=,<><<,>>,&,|LIKE,GLOB,MATCH,REGEXPIS NULL,IS NOT NULLIN,NOT INNOT LIKE,NOT GLOB,NOT MATCH,NOT REGEXPTesting
Example Impact
Before (incorrect):
After (correct):
Breaking Changes
EXISTS/NOT EXISTSreturn types: Generated Go methods now returnbool(and emit variables namedexists/not_exists) instead of the previousint64placeholder. Projects that already consume these helpers must update their call sites to expect a boolean result.NOT 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,idinBarNotExists).Related Issues
Fixes parsing issues with SQLite comparison operators and ORDER BY clauses that could lead to incorrect SQL generation and runtime errors.