diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2013-08-07 22:48:48 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2013-08-07 22:48:48 -0700 |
commit | 4d8f23489e969ed3d61357b543b7a5607e57449e (patch) | |
tree | 15f354d60c61ae0f0847a715bb22f7975cc4295a /activerecord/lib/active_record/connection_adapters | |
parent | 5ac2341fab689344991b2a4817bd2bc8b3edac9d (diff) | |
parent | 0d435cc24bbf7241df63fcd15724ce2a21d4f9dd (diff) | |
download | rails-4d8f23489e969ed3d61357b543b7a5607e57449e.tar.gz rails-4d8f23489e969ed3d61357b543b7a5607e57449e.tar.bz2 rails-4d8f23489e969ed3d61357b543b7a5607e57449e.zip |
Merge pull request #11802 from ko1/fix_field_encoding_for_mysql
Set field encoding to client_encoding for mysql adapter.
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters')
-rwxr-xr-x[-rw-r--r--] | activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb | 3 | ||||
-rwxr-xr-x[-rw-r--r--] | activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb | 4 | ||||
-rwxr-xr-x[-rw-r--r--] | activerecord/lib/active_record/connection_adapters/mysql_adapter.rb | 8 |
3 files changed, 14 insertions, 1 deletions
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 5b25b26164..daa9d902fe 100644..100755 --- 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 index 28c7cff1cc..92796c996e 100644..100755 --- 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 index fbe6ecf5f1..15b5452850 100644..100755 --- 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 |