instance method
configure_connection
Ruby on Rails edge
Since v4.0.13 Private — implementation detail, not part of the public APISignature
configure_connection()
No documentation comment.
Source
# File activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb, line 999
def configure_connection
super
variables = @config.fetch(:variables, {}).stringify_keys
# Increase timeout so the server doesn't disconnect us.
# Set to false in config to skip.
unless @config[:wait_timeout] == false
wait_timeout = self.class.type_cast_config_to_integer(@config[:wait_timeout])
wait_timeout = 2147483 unless wait_timeout.is_a?(Integer)
variables["wait_timeout"] = wait_timeout
end
defaults = [":default", :default].to_set
# Make MySQL reject illegal values rather than truncating or blanking them, see
# https://dev.mysql.com/doc/refman/en/sql-mode.html#sqlmode_traditional
# If the user has provided another value for sql_mode, don't replace it.
# Set sql_mode to false or :default in variables to skip.
if variables.key?("sql_mode")
sql_mode_value = variables.delete("sql_mode")
unless sql_mode_value == false || defaults.include?(sql_mode_value)
sql_mode = quote(sql_mode_value)
end
elsif !defaults.include?(strict_mode?)
if strict_mode?
sql_mode = "CONCAT(@@sql_mode, ',TRADITIONAL')"
else
sql_mode = "REPLACE(@@sql_mode, 'STRICT_TRANS_TABLES', '')"
sql_mode = "REPLACE(#{sql_mode}, 'STRICT_ALL_TABLES', '')"
sql_mode = "REPLACE(#{sql_mode}, 'TRADITIONAL', '')"
end
sql_mode = "CONCAT(#{sql_mode}, ',NO_AUTO_VALUE_ON_ZERO')"
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.filter_map do |k, v|
if defaults.include?(v)
"@@SESSION.#{k} = DEFAULT" # Sets the value to the global or compile default
elsif !v.nil?
"@@SESSION.#{k} = #{quote(v)}"
end
end.join(", ")
# ...and send them all in one query
intent = QueryIntent.new(
adapter: self,
processed_sql: "SET #{encoding} #{sql_mode_assignment} #{variable_assignments}",
name: "SCHEMA"
)
intent.execute!
intent.finish
end
Defined in activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb line 999
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter