From 501e979e186a3861581aa54f9930421223688d01 Mon Sep 17 00:00:00 2001 From: nanaya Date: Fri, 19 Aug 2016 00:08:19 +0900 Subject: Use proper casting --- .../lib/active_record/connection_adapters/postgresql_adapter.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb index 03ee0eec5b..08c81e7478 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb @@ -772,9 +772,9 @@ module ActiveRecord SELECT exists( SELECT * FROM pg_proc INNER JOIN pg_cast - ON casttarget::text::oidvector = proargtypes + ON ARRAY[casttarget]::oidvector = proargtypes WHERE proname = 'lower' - AND castsource = '#{column.sql_type}'::regtype::oid + AND castsource = #{quote column.sql_type}::regtype ) end_sql execute_and_clear(sql, "SCHEMA", []) do |result| -- cgit v1.2.3 From 4c2f7ee36a623090d276ef811d959adb0ecff743 Mon Sep 17 00:00:00 2001 From: nanaya Date: Thu, 18 Aug 2016 21:56:15 +0900 Subject: Fix case insensitive check for text column in pg There's no 'text to text' casting in the cast table so the feature detection fails. --- .../connection_adapters/postgresql_adapter.rb | 4 ++++ .../adapters/postgresql/case_insensitive_test.rb | 26 ++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 activerecord/test/cases/adapters/postgresql/case_insensitive_test.rb diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb index 08c81e7478..c9a0287bca 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb @@ -770,6 +770,10 @@ module ActiveRecord @case_insensitive_cache[column.sql_type] ||= begin sql = <<-end_sql SELECT exists( + SELECT * FROM pg_proc + WHERE proname = 'lower' + AND proargtypes = ARRAY[#{quote column.sql_type}::regtype]::oidvector + ) OR exists( SELECT * FROM pg_proc INNER JOIN pg_cast ON ARRAY[casttarget]::oidvector = proargtypes diff --git a/activerecord/test/cases/adapters/postgresql/case_insensitive_test.rb b/activerecord/test/cases/adapters/postgresql/case_insensitive_test.rb new file mode 100644 index 0000000000..d04e55f5bf --- /dev/null +++ b/activerecord/test/cases/adapters/postgresql/case_insensitive_test.rb @@ -0,0 +1,26 @@ +require "cases/helper" + +class PostgresqlCaseInsensitiveTest < ActiveRecord::PostgreSQLTestCase + class Default < ActiveRecord::Base; end + + def test_case_insensitiveness + connection = ActiveRecord::Base.connection + table = Default.arel_table + + column = Default.columns_hash["char1"] + comparison = connection.case_insensitive_comparison table, :char1, column, nil + assert_match /lower/i, comparison.to_sql + + column = Default.columns_hash["char2"] + comparison = connection.case_insensitive_comparison table, :char2, column, nil + assert_match /lower/i, comparison.to_sql + + column = Default.columns_hash["char3"] + comparison = connection.case_insensitive_comparison table, :char3, column, nil + assert_match /lower/i, comparison.to_sql + + column = Default.columns_hash["multiline_default"] + comparison = connection.case_insensitive_comparison table, :multiline_default, column, nil + assert_match /lower/i, comparison.to_sql + end +end -- cgit v1.2.3