Skip to content

Commit ae19168

Browse files
committed
fix(sqlite): Convert boolean literals (true/false) to bool type
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 #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/
1 parent 9d6b46c commit ae19168

File tree

6 files changed

+132
-6
lines changed

6 files changed

+132
-6
lines changed

internal/endtoend/testdata/select_true_literal/sqlite/db/db.go

Lines changed: 31 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/endtoend/testdata/select_true_literal/sqlite/db/models.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/endtoend/testdata/select_true_literal/sqlite/db/query.sql.go

Lines changed: 71 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
-- name: SelectTrue :one
2+
SELECT true;
3+
4+
-- name: SelectFalse :one
5+
SELECT false;
6+
7+
-- name: SelectTrueWithAlias :one
8+
SELECT true AS is_active;
9+
10+
-- name: SelectMultipleBooleans :one
11+
SELECT true AS col_a, false AS col_b, true AS col_c;
12+
13+
-- name: SelectOne :one
14+
SELECT 1;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"version": "1",
3+
"packages": [
4+
{
5+
"path": "db",
6+
"engine": "sqlite",
7+
"queries": "query.sql"
8+
}
9+
]
10+
}

internal/engine/sqlite/convert.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -752,13 +752,8 @@ func (c *cc) convertLiteral(n *parser.Expr_literalContext) ast.Node {
752752
}
753753

754754
if literal.TRUE_() != nil || literal.FALSE_() != nil {
755-
var i int64
756-
if literal.TRUE_() != nil {
757-
i = 1
758-
}
759-
760755
return &ast.A_Const{
761-
Val: &ast.Integer{Ival: i},
756+
Val: &ast.Boolean{Boolval: literal.TRUE_() != nil},
762757
Location: n.GetStart().GetStart(),
763758
}
764759
}

0 commit comments

Comments
 (0)