Skip to content

Commit 34bebf3

Browse files
committed
Use TRUE and FALSE for booleans in SQLite
Previously, queries generated with boolean comparisons for MySQL and Postgres used `TRUE` and `FALSE` (these are actual booleans in Postgres and aliases for `1`/`0` in MySQL) but used `1` and `0` for SQLite. This makes it more difficult to write database-agnostic query assertions, since the values are different. SQLite 3.23.0 added support for `TRUE` and `FALSE` as aliases for `1`/`0` (similar to MySQL). A [previous commit][1] bumped the minimum required SQLite version in Active Record to 3.23.0, and this commit updates the boolean query generation for SQLite to use `TRUE` and `FALSE`. [1]: 809abd3
1 parent c70378b commit 34bebf3

File tree

3 files changed

+4
-15
lines changed

3 files changed

+4
-15
lines changed

activerecord/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
* Use `TRUE` and `FALSE` for SQLite queries with boolean columns.
2+
3+
*Hartley McGuire*
4+
15
* Bump minimum supported SQLite to 3.23.0.
26

37
*Hartley McGuire*

activerecord/lib/arel/visitors/sqlite.rb

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,6 @@ def visit_Arel_Nodes_SelectStatement(o, collector)
6868
super
6969
end
7070

71-
def visit_Arel_Nodes_True(o, collector)
72-
collector << "1"
73-
end
74-
75-
def visit_Arel_Nodes_False(o, collector)
76-
collector << "0"
77-
end
78-
7971
def visit_Arel_Nodes_IsNotDistinctFrom(o, collector)
8072
collector = visit o.left, collector
8173
collector << " IS "

activerecord/test/cases/arel/visitors/sqlite_test.rb

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,6 @@ def compile(node)
2525
assert_equal "", @visitor.accept(node, Collectors::SQLString.new).value
2626
end
2727

28-
it "does not support boolean" do
29-
node = Nodes::True.new()
30-
assert_equal "1", @visitor.accept(node, Collectors::SQLString.new).value
31-
node = Nodes::False.new()
32-
assert_equal "0", @visitor.accept(node, Collectors::SQLString.new).value
33-
end
34-
3528
describe "Nodes::IsNotDistinctFrom" do
3629
it "should construct a valid generic SQL statement" do
3730
test = Table.new(:users)[:name].is_not_distinct_from "Aaron Patterson"

0 commit comments

Comments
 (0)