Skip to content

Commit 213ec96

Browse files
committed
[postgres] improve Range's type cast - thus fixing minor quoting failure on AR 4.x
1 parent 1ff0898 commit 213ec96

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

lib/arjdbc/postgresql/adapter.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -850,10 +850,11 @@ def quote(value, column = nil)
850850
else super
851851
end
852852
when Range
853-
if column.type.to_s[-5..-1] == 'range' # :'xxxrange' only in AR-4.0
853+
sql_type = column.respond_to?(:sql_type) && column.sql_type
854+
if sql_type && sql_type[-5, 5] == 'range' && AR4_COMPAT
854855
column_class = ::ActiveRecord::ConnectionAdapters::PostgreSQLColumn
855856
escaped = quote_string(column_class.range_to_string(value))
856-
"'#{escaped}'::#{column.sql_type}"
857+
"'#{escaped}'::#{sql_type}"
857858
else super
858859
end
859860
when IPAddr

test/db/postgresql/quoting_test.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,10 @@ def test_quote_time_usec
6262

6363
def test_quote_range
6464
range = "1,2]'; SELECT * FROM users; --".."a"
65-
c = Column.new(nil, nil, OID::Range.new(:integer), 'int8range')
66-
assert_equal "[1,2]''; SELECT * FROM users; --,a]::int8range", connection.quote(range, c)
65+
c = Column.new(nil, nil, 'int8range')
66+
assert_equal "'[1,2]''; SELECT * FROM users; --,a]'::int8range", connection.quote(range, c)
67+
#c = PostgreSQLColumn.new(nil, nil, OID::Range.new(:integer), 'int8range')
68+
#assert_equal "'[1,2]''; SELECT * FROM users; --,a]'::int8range", @conn.quote(range, c)
6769
end if OID
6870

6971
end

0 commit comments

Comments
 (0)