Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #11802 from ko1/fix_field_encoding_for_mysql

Set field encoding to client_encoding for mysql adapter.
  • Loading branch information...
commit 166b235c0e8d7b92bda5dc089230fb4b8ba67528 1 parent d9f28aa
@tenderlove tenderlove authored senny committed
View
3  activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb 100644 → 100755
@@ -460,7 +460,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
@@ -270,6 +270,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
0  activerecord/test/cases/base_test.rb 100644 → 100755
File mode changed

2 comments on commit 166b235

@jeremy
Owner

This changes the field encoding on a stable 4.0.x release - should save that for 4.1

@senny
Owner

This backport is directly related to aef61b4 if we revert, we should remove both.

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