Skip to content
Browse files

Set field encoding to client_encoding for mysql adapter.

  • Loading branch information...
1 parent 765b8aa commit 0d435cc24bbf7241df63fcd15724ce2a21d4f9dd @ko1 ko1 committed
View
3 activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb 100644 → 100755
@@ -469,7 +469,8 @@ def columns(table_name)#:nodoc:
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
View
4 activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb 100644 → 100755
@@ -269,6 +269,10 @@ def configure_connection
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
View
8 activerecord/lib/active_record/connection_adapters/mysql_adapter.rb 100644 → 100755
@@ -559,6 +559,14 @@ def select(sql, name = nil, binds = [])
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
View
2 activerecord/test/cases/base_test.rb 100644 → 100755
@@ -585,8 +585,6 @@ def test_readonly_attributes
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

0 comments on commit 0d435cc

Please sign in to comment.
Something went wrong with that request. Please try again.