From 8d24c6ba5ebbb8892167fd8e09e95c585cb08810 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Wed, 17 Feb 2021 18:12:36 +0000 Subject: [PATCH] Revert "Merge pull request #41232 from code4me/fix-malformed-packet-master" This reverts commit 8b3fc5ce30629cb098e923396c3eb797365c88d2, reversing changes made to 668c1409f1592586fd2099f1f3c535da4d994ced. See #41403. --- .../abstract_mysql_adapter.rb | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 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 47e51e8020..dc953892d1 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb @@ -751,11 +751,6 @@ module ActiveRecord wait_timeout = 2147483 unless wait_timeout.is_a?(Integer) variables["wait_timeout"] = wait_timeout - # Set the collation of the connection character set. - if @config[:collation] - variables["collation_connection"] = @config[:collation] - end - defaults = [":default", :default].to_set # Make MySQL reject illegal values rather than truncating or blanking them, see @@ -775,6 +770,15 @@ module ActiveRecord end sql_mode_assignment = "@@SESSION.sql_mode = #{sql_mode}, " if sql_mode + # NAMES does not have an equals sign, see + # https://dev.mysql.com/doc/refman/en/set-names.html + # (trailing comma because variable_assignments will always have content) + if @config[:encoding] + encoding = +"NAMES #{@config[:encoding]}" + encoding << " COLLATE #{@config[:collation]}" if @config[:collation] + encoding << ", " + end + # Gather up all of the SET variables... variable_assignments = variables.map do |k, v| if defaults.include?(v) @@ -786,7 +790,7 @@ module ActiveRecord end.compact.join(", ") # ...and send them all in one query - execute("SET #{sql_mode_assignment} #{variable_assignments}", "SCHEMA") + execute("SET #{encoding} #{sql_mode_assignment} #{variable_assignments}", "SCHEMA") end def column_definitions(table_name) # :nodoc: