Translate MySQL CONVERT() expressions to SQLite#356
Open
Conversation
Promote the %simpleExpr_factored fragment to a real "simpleExprBody" rule so it creates its own AST node. This separates the core expression (CONVERT, CAST, literals, etc.) from trailing modifiers (COLLATE, CONCAT_PIPES) that remain in the parent "simpleExpr" node, making individual expression handlers simpler.
SQLite doesn't support the CONVERT() function. Translate its two forms: - CONVERT(expr, type) is equivalent to CAST(expr AS type). - CONVERT(expr USING charset) is a character set conversion that is a no-op in SQLite, as all text is stored as UTF-8. Fixes #344
Member
Author
|
The Query Monitor tests failure is unrelated to this PR and I will address it separately. It seems that QM 4.0 is incompatbible with our integration. |
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.
Summary
Fixes #344.
MySQL's
CONVERT()function was passed through to SQLite unchanged, causing queries likeSELECT CONVERT('Customer' USING utf8mb4) COLLATE utf8mb4_binto fail with a syntax error.This PR has two parts:
Extract
simpleExprBodyas a named grammar rule. The%simpleExpr_factoredfragment is promoted to a realsimpleExprBodyrule so it creates its own AST node. This separates the core expression (CONVERT, CAST, literals, etc.) from trailing modifiers (COLLATE, CONCAT_PIPES) that remain in the parentsimpleExprnode, making individual expression handlers simpler.Translate
CONVERT()expressions. Adds explicit handling for both forms ofCONVERT()in the AST-based driver:CONVERT(expr, type)is translated toCAST(expr AS type), reusing the existingcastTypetranslation.CONVERT(expr USING charset)is reduced to just the expression, as SQLite stores all text as UTF-8 and charset conversions are not needed.Test plan
testConverttranslation test — verifies SQL-to-SQL translation for both CONVERT forms and COLLATE.testConvertExpression— verifies CONVERT with type casting (BINARY, CHAR, SIGNED, UNSIGNED, DECIMAL, DATE).testConvertUsingExpression— verifies CONVERT with charset conversion (utf8mb4, utf8, latin1).testConvertUsingWithCollate— verifies the exact query from CONVERT() queries fail with error #344.testConvertWithColumnReferences— verifies CONVERT with column references in SELECT, WHERE, and ORDER BY.