diff options
author | Sean Griffin <sean@seantheprogrammer.com> | 2017-09-26 20:08:20 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-26 20:08:20 -0400 |
commit | 48ef5e0ad500bdba706f10b65456f3b03b556212 (patch) | |
tree | 287cf94ccee0a1d626fe2525f94405bdd3b5c506 /activerecord/lib | |
parent | 40a63e52d275a94227761f79b4a2544aaad8210a (diff) | |
parent | 51b6c3429f41ebbc571b8fcbe7c21d3131b832d8 (diff) | |
download | rails-48ef5e0ad500bdba706f10b65456f3b03b556212.tar.gz rails-48ef5e0ad500bdba706f10b65456f3b03b556212.tar.bz2 rails-48ef5e0ad500bdba706f10b65456f3b03b556212.zip |
Merge pull request #30725 from cheerful/record-milliseconds-in-postgres-timestamp-ranges
Use `ActiveRecord::ConnectionAdapters::Quoting.quote` to quote bounds for a PostgreSQL range
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/postgresql/oid/range.rb | 2 | ||||
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb | 8 |
2 files changed, 9 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/oid/range.rb b/activerecord/lib/active_record/connection_adapters/postgresql/oid/range.rb index 7d5d7d91e6..a89aa5ea09 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/oid/range.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/oid/range.rb @@ -35,7 +35,7 @@ module ActiveRecord if value.is_a?(::Range) from = type_cast_single_for_database(value.begin) to = type_cast_single_for_database(value.end) - "[#{from},#{to}#{value.exclude_end? ? ')' : ']'}" + ::Range.new(from, to, value.exclude_end?) else super end diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb b/activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb index a0a22ba0f1..9fdeab06c1 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb @@ -101,6 +101,8 @@ module ActiveRecord end when OID::Array::Data _quote(encode_array(value)) + when Range + _quote(encode_range(value)) else super end @@ -117,6 +119,8 @@ module ActiveRecord value.to_s when OID::Array::Data encode_array(value) + when Range + encode_range(value) else super end @@ -133,6 +137,10 @@ module ActiveRecord result end + def encode_range(range) + "[#{type_cast(range.first)},#{type_cast(range.last)}#{range.exclude_end? ? ')' : ']'}" + end + def determine_encoding_of_strings_in_array(value) case value when ::Array then determine_encoding_of_strings_in_array(value.first) |