aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2014-03-12 10:51:10 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2014-03-12 10:51:10 -0300
commit591b8f395d101ad1a3b009b98de0e6bd2a5d6222 (patch)
tree9fc4ef3424de7f2fff454e0b48727900ada8b967 /activerecord/lib
parent79ceae6241f612f866ff2b8670788feaf199b96f (diff)
parent501ae92a32285528c8bbdcf2af422eadb6a63c0e (diff)
downloadrails-591b8f395d101ad1a3b009b98de0e6bd2a5d6222.tar.gz
rails-591b8f395d101ad1a3b009b98de0e6bd2a5d6222.tar.bz2
rails-591b8f395d101ad1a3b009b98de0e6bd2a5d6222.zip
Merge pull request #13040 from kamipo/case_sensitive_comparison
Only use BINARY for mysql case sensitive uniqueness check when column has a case insensitive collation. Conflicts: activerecord/CHANGELOG.md
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract_adapter.rb5
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb8
-rw-r--r--activerecord/lib/active_record/validations/uniqueness.rb3
3 files changed, 14 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
index 11b28a4858..496153af83 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
@@ -340,6 +340,11 @@ module ActiveRecord
node
end
+ def case_sensitive_comparison(table, attribute, column, value)
+ value = case_sensitive_modifier(value) unless value.nil?
+ table[attribute].eq(value)
+ end
+
def case_insensitive_comparison(table, attribute, column, value)
table[attribute].lower.eq(table.lower(value))
end
diff --git a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
index baac9522b6..9a819720f7 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
@@ -592,6 +592,14 @@ module ActiveRecord
Arel::Nodes::Bin.new(node)
end
+ def case_sensitive_comparison(table, attribute, column, value)
+ if column.case_sensitive?
+ table[attribute].eq(value)
+ else
+ super
+ end
+ end
+
def case_insensitive_comparison(table, attribute, column, value)
if column.case_sensitive?
super
diff --git a/activerecord/lib/active_record/validations/uniqueness.rb b/activerecord/lib/active_record/validations/uniqueness.rb
index 82c2b9439b..71c71cb4b1 100644
--- a/activerecord/lib/active_record/validations/uniqueness.rb
+++ b/activerecord/lib/active_record/validations/uniqueness.rb
@@ -68,8 +68,7 @@ module ActiveRecord
# will use SQL LOWER function before comparison, unless it detects a case insensitive collation
klass.connection.case_insensitive_comparison(table, attribute, column, value)
else
- value = klass.connection.case_sensitive_modifier(value) unless value.nil?
- table[attribute].eq(value)
+ klass.connection.case_sensitive_comparison(table, attribute, column, value)
end
end