From 289ec49f469533c89fbca8303dbfd7b1a43d1197 Mon Sep 17 00:00:00 2001 From: Taishi Kasuga Date: Tue, 16 Jun 2015 10:08:33 +0900 Subject: Fix the MySQL column type `SET` registration bug --- activerecord/test/cases/connection_adapters/mysql_type_lookup_test.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/activerecord/test/cases/connection_adapters/mysql_type_lookup_test.rb b/activerecord/test/cases/connection_adapters/mysql_type_lookup_test.rb index 80244d1439..2749273884 100644 --- a/activerecord/test/cases/connection_adapters/mysql_type_lookup_test.rb +++ b/activerecord/test/cases/connection_adapters/mysql_type_lookup_test.rb @@ -22,6 +22,10 @@ module ActiveRecord assert_lookup_type :string, "SET('one', 'two', 'three')" end + def test_set_type_with_value_matching_other_type + assert_lookup_type :string, "SET('unicode', '8bit', 'none', 'time')" + end + def test_enum_type_with_value_matching_other_type assert_lookup_type :string, "ENUM('unicode', '8bit', 'none')" end -- cgit v1.2.3 From 206cf5193808b41c45fd287e5134dffa961a88de Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Sat, 20 Jun 2015 22:56:45 +0900 Subject: Fix infinite loop and lookup miss when `SET` type includes other types This commit fixes the following problems: * cause infinit type lookup loop when SET includes aliased types * For example: when SET('set') includes aliased type `set`, then aliased `varchar('set')` by type lookup, but type lookup infinit matching same rule. * cause type lookup miss when SET includes registered types * For example: when SET('time') includes registered type `time`, then aliased `varchar('time')` by type lookup, then matching `time` type. --- .../active_record/connection_adapters/abstract_mysql_adapter.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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 00e3d2965b..7e3a705449 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb @@ -789,7 +789,6 @@ module ActiveRecord register_integer_type m, %r(^tinyint)i, limit: 1 m.alias_type %r(tinyint\(1\))i, 'boolean' if emulate_booleans - m.alias_type %r(set)i, 'varchar' m.alias_type %r(year)i, 'integer' m.alias_type %r(bit)i, 'binary' @@ -798,6 +797,12 @@ module ActiveRecord .split(',').map{|enum| enum.strip.length - 2}.max MysqlString.new(limit: limit) end + + m.register_type(%r(^set)i) do |sql_type| + limit = sql_type[/^set\((.+)\)/i, 1] + .split(',').map{|set| set.strip.length - 1}.sum - 1 + MysqlString.new(limit: limit) + end end def register_integer_type(mapping, key, options) # :nodoc: -- cgit v1.2.3