fix(mysql, sqlite): convert boolean literal to bool type#4282
Closed
kitagry wants to merge 3 commits into
Closed
Conversation
Previously, MySQL boolean literals like `SELECT true` were incorrectly converted to int32 type, while table columns with BOOL/BOOLEAN/TINYINT(1) types were correctly converted to bool. The TiDB parser represents boolean literals as mysql.TypeLonglong with value 1 (true) or 0 (false), which was indistinguishable from integer literals like `SELECT 1`. This fix: - Detects boolean literals by examining the original SQL text - Converts `true`/`false` (case-insensitive) to bool type - Preserves integer literals like `SELECT 1` as int32 - Supports all case variations: TRUE, True, FALSE, False, etc. Test cases: - SELECT true/false → bool - SELECT TRUE/FALSE → bool - SELECT true AS col → bool - SELECT 1/0 → int32 (unchanged)
Previously, SQLite boolean literals like `SELECT true` were incorrectly converted to int64 type, while PostgreSQL correctly returned bool. The ANTLR parser provides TRUE_() and FALSE_() tokens, but these were originally implemented to return Integer in PR sqlc-dev#1447 (2022-02-19) without specific reasoning, likely because SQLite internally uses integers (1/0) for boolean values. This fix changes the TRUE_()/FALSE_() handling to return ast.Boolean instead of ast.Integer, aligning SQLite's behavior with PostgreSQL and providing a more type-safe interface. Test results: - SELECT true/false → bool (was int64) - SELECT TRUE/FALSE → bool (was int64) - SELECT 1 → int64 (unchanged) Added test: internal/endtoend/testdata/select_true_literal/sqlite/
Collaborator
|
🤖 Automated message This PR has been closed because it has merge conflicts with Generated by Claude Code |
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.
Previously, MySQL boolean literals like
SELECT truewere incorrectly converted to int32 type, while table columns with BOOL/BOOLEAN/TINYINT(1) types were correctly converted to bool.