Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix malformed packet error in MySQL statement for connection configuration #41232

Merged
merged 1 commit into from Jan 26, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -751,6 +751,11 @@ def configure_connection
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
Expand All @@ -770,15 +775,6 @@ def configure_connection
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)
Expand All @@ -790,7 +786,7 @@ def configure_connection
end.compact.join(", ")

# ...and send them all in one query
execute("SET #{encoding} #{sql_mode_assignment} #{variable_assignments}", "SCHEMA")
execute("SET #{sql_mode_assignment} #{variable_assignments}", "SCHEMA")
end

def column_definitions(table_name) # :nodoc:
Expand Down