Stringify variables names for mysql connections
For mysql2/mysql adapters, `sql_mode` variable name set in `database.yml` as string, was ignored and `sql_mode` was set to use strict mode. Fixes #14895
This commit is contained in:
parent
fd92437112
commit
7e8b062823
@ -1,3 +1,12 @@
|
||||
* Stringify all variables keys of mysql connection configuration.
|
||||
|
||||
When `sql_mode` variable for mysql adapters set in configuration as `String`
|
||||
was ignored and overwritten by strict mode option.
|
||||
|
||||
Fixes #14895
|
||||
|
||||
*Paul Nikitochkin*
|
||||
|
||||
* When using a custom `join_table` name on a `habtm`, rails was not saving it
|
||||
on Reflections. This causes a problem when rails loads fixtures, because it
|
||||
uses the reflections to set database with fixtures.
|
||||
|
@ -765,22 +765,22 @@ def column_for(table_name, column_name)
|
||||
end
|
||||
|
||||
def configure_connection
|
||||
variables = @config[:variables] || {}
|
||||
variables = @config.fetch(:variables, {}).stringify_keys
|
||||
|
||||
# By default, MySQL 'where id is null' selects the last inserted id.
|
||||
# Turn this off. http://dev.rubyonrails.org/ticket/6778
|
||||
variables[:sql_auto_is_null] = 0
|
||||
variables['sql_auto_is_null'] = 0
|
||||
|
||||
# Increase timeout so the server doesn't disconnect us.
|
||||
wait_timeout = @config[:wait_timeout]
|
||||
wait_timeout = 2147483 unless wait_timeout.is_a?(Fixnum)
|
||||
variables[:wait_timeout] = self.class.type_cast_config_to_integer(wait_timeout)
|
||||
variables['wait_timeout'] = self.class.type_cast_config_to_integer(wait_timeout)
|
||||
|
||||
# Make MySQL reject illegal values rather than truncating or blanking them, see
|
||||
# http://dev.mysql.com/doc/refman/5.0/en/server-sql-mode.html#sqlmode_strict_all_tables
|
||||
# If the user has provided another value for sql_mode, don't replace it.
|
||||
if strict_mode? && !variables.has_key?(:sql_mode)
|
||||
variables[:sql_mode] = 'STRICT_ALL_TABLES'
|
||||
if strict_mode? && !variables.has_key?('sql_mode')
|
||||
variables['sql_mode'] = 'STRICT_ALL_TABLES'
|
||||
end
|
||||
|
||||
# NAMES does not have an equals sign, see
|
||||
|
@ -151,6 +151,14 @@ def test_mysql_set_session_variable
|
||||
end
|
||||
end
|
||||
|
||||
def test_mysql_sql_mode_variable_overides_strict_mode
|
||||
run_without_connection do |orig_connection|
|
||||
ActiveRecord::Base.establish_connection(orig_connection.deep_merge(variables: { 'sql_mode' => 'ansi' }))
|
||||
result = ActiveRecord::Base.connection.exec_query 'SELECT @@SESSION.sql_mode'
|
||||
assert_not_equal [['STRICT_ALL_TABLES']], result.rows
|
||||
end
|
||||
end
|
||||
|
||||
def test_mysql_set_session_variable_to_default
|
||||
run_without_connection do |orig_connection|
|
||||
ActiveRecord::Base.establish_connection(orig_connection.deep_merge({:variables => {:default_week_format => :default}}))
|
||||
|
@ -77,6 +77,14 @@ def test_mysql_set_session_variable
|
||||
end
|
||||
end
|
||||
|
||||
def test_mysql_sql_mode_variable_overides_strict_mode
|
||||
run_without_connection do |orig_connection|
|
||||
ActiveRecord::Base.establish_connection(orig_connection.deep_merge(variables: { 'sql_mode' => 'ansi' }))
|
||||
result = ActiveRecord::Base.connection.exec_query 'SELECT @@SESSION.sql_mode'
|
||||
assert_not_equal [['STRICT_ALL_TABLES']], result.rows
|
||||
end
|
||||
end
|
||||
|
||||
def test_mysql_set_session_variable_to_default
|
||||
run_without_connection do |orig_connection|
|
||||
ActiveRecord::Base.establish_connection(orig_connection.deep_merge({:variables => {:default_week_format => :default}}))
|
||||
|
Loading…
Reference in New Issue
Block a user