Skip to content

Commit 576db3b

Browse files
committed
Use TRUE and FALSE for more SQLite queries
A [previous commit][0] updated the SQLite Arel visitor to use `TRUE` and `FALSE` literals instead of `1` and `0` for `True` and `False` Arel Nodes. This commit takes the change further by making SQLite quote `true` and `false` values as `TRUE` and `FALSE` instead of `1` and `0`. This additionally required adding support for `DEFAULT TRUE` and `DEFAULT FALSE` SQLite column definitions (which is more correct anyways in case someone made `TRUE` or `FALSE` the default value of a column using `default: -> { "TRUE" }`, etc). [0]: 34bebf3
1 parent c593a74 commit 576db3b

File tree

3 files changed

+3
-9
lines changed

3 files changed

+3
-9
lines changed

activerecord/lib/active_record/connection_adapters/sqlite3/quoting.rb

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,18 +80,10 @@ def quoted_binary(value)
8080
"x'#{value.hex}'"
8181
end
8282

83-
def quoted_true
84-
"1"
85-
end
86-
8783
def unquoted_true
8884
1
8985
end
9086

91-
def quoted_false
92-
"0"
93-
end
94-
9587
def unquoted_false
9688
0
9789
end

activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,8 @@ def extract_value_from_default(default)
564564
# Binary columns
565565
when /x'(.*)'/
566566
[ $1 ].pack("H*")
567+
when "TRUE", "FALSE"
568+
default
567569
else
568570
# Anything else is blank or some function
569571
# and we can't know the value of that, so return nil.

activerecord/test/cases/adapters/sqlite3/bind_parameter_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def test_where_with_float_for_string_column_using_bind_parameters
2222
end
2323

2424
def test_where_with_boolean_for_string_column_using_bind_parameters
25-
assert_quoted_as "0", false
25+
assert_quoted_as "FALSE", false
2626
end
2727

2828
def test_where_with_decimal_for_string_column_using_bind_parameters

0 commit comments

Comments
 (0)