From 0d435cc24bbf7241df63fcd15724ce2a21d4f9dd Mon Sep 17 00:00:00 2001 From: Koichi Sasada Date: Thu, 8 Aug 2013 14:44:39 +0900 Subject: Set field encoding to client_encoding for mysql adapter. --- .../active_record/connection_adapters/abstract_mysql_adapter.rb | 3 ++- .../lib/active_record/connection_adapters/mysql2_adapter.rb | 4 ++++ .../lib/active_record/connection_adapters/mysql_adapter.rb | 8 ++++++++ activerecord/test/cases/base_test.rb | 2 -- 4 files changed, 14 insertions(+), 3 deletions(-) mode change 100644 => 100755 activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb mode change 100644 => 100755 activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb mode change 100644 => 100755 activerecord/lib/active_record/connection_adapters/mysql_adapter.rb mode change 100644 => 100755 activerecord/test/cases/base_test.rb diff --git a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb old mode 100644 new mode 100755 index 5b25b26164..daa9d902fe --- a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb @@ -469,7 +469,8 @@ module ActiveRecord sql = "SHOW FULL FIELDS FROM #{quote_table_name(table_name)}" execute_and_free(sql, 'SCHEMA') do |result| each_hash(result).map do |field| - new_column(field[:Field], field[:Default], field[:Type], field[:Null] == "YES", field[:Collation], field[:Extra]) + field_name = set_field_encoding(field[:Field]) + new_column(field_name, field[:Default], field[:Type], field[:Null] == "YES", field[:Collation], field[:Extra]) end end end diff --git a/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb b/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb old mode 100644 new mode 100755 index 28c7cff1cc..92796c996e --- a/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb @@ -269,6 +269,10 @@ module ActiveRecord def version @version ||= @connection.info[:version].scan(/^(\d+)\.(\d+)\.(\d+)/).flatten.map { |v| v.to_i } end + + def set_field_encoding field_name + field_name + end end end end diff --git a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb old mode 100644 new mode 100755 index fbe6ecf5f1..15b5452850 --- a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb @@ -559,6 +559,14 @@ module ActiveRecord def version @version ||= @connection.server_info.scan(/^(\d+)\.(\d+)\.(\d+)/).flatten.map { |v| v.to_i } end + + def set_field_encoding field_name + field_name.force_encoding(client_encoding) + if internal_enc = Encoding.default_internal + field_name = field_name.encoding(internal_enc) + end + field_name + end end end end diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb old mode 100644 new mode 100755 index e50e32900e..c91cf89f6d --- a/activerecord/test/cases/base_test.rb +++ b/activerecord/test/cases/base_test.rb @@ -585,8 +585,6 @@ class BasicsTest < ActiveRecord::TestCase end def test_unicode_column_name - skip "not on mysql" if current_adapter?(:MysqlAdapter) - columns = Weird.columns_hash.keys weird = Weird.create(:なまえ => 'たこ焼き仮面') assert_equal 'たこ焼き仮面', weird.なまえ end -- cgit v1.2.3