Merge pull request #14896 from jetthoughts/14895_overide_strict_by_sql_mode
Symbolize variables of mysql/mysql2 connection configuration Conflicts: activerecord/CHANGELOG.md
This commit is contained in:
commit
e99e23d115
@ -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*
|
||||||
|
|
||||||
* Ensure SQLite3 statements are closed on errors.
|
* Ensure SQLite3 statements are closed on errors.
|
||||||
|
|
||||||
Fixes: #13631
|
Fixes: #13631
|
||||||
|
@ -765,22 +765,22 @@ def column_for(table_name, column_name)
|
|||||||
end
|
end
|
||||||
|
|
||||||
def configure_connection
|
def configure_connection
|
||||||
variables = @config[:variables] || {}
|
variables = @config.fetch(:variables, {}).stringify_keys
|
||||||
|
|
||||||
# By default, MySQL 'where id is null' selects the last inserted id.
|
# By default, MySQL 'where id is null' selects the last inserted id.
|
||||||
# Turn this off. http://dev.rubyonrails.org/ticket/6778
|
# 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.
|
# Increase timeout so the server doesn't disconnect us.
|
||||||
wait_timeout = @config[:wait_timeout]
|
wait_timeout = @config[:wait_timeout]
|
||||||
wait_timeout = 2147483 unless wait_timeout.is_a?(Fixnum)
|
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
|
# 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
|
# 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 the user has provided another value for sql_mode, don't replace it.
|
||||||
if strict_mode? && !variables.has_key?(:sql_mode)
|
if strict_mode? && !variables.has_key?('sql_mode')
|
||||||
variables[:sql_mode] = 'STRICT_ALL_TABLES'
|
variables['sql_mode'] = 'STRICT_ALL_TABLES'
|
||||||
end
|
end
|
||||||
|
|
||||||
# NAMES does not have an equals sign, see
|
# NAMES does not have an equals sign, see
|
||||||
|
@ -151,6 +151,14 @@ def test_mysql_set_session_variable
|
|||||||
end
|
end
|
||||||
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
|
def test_mysql_set_session_variable_to_default
|
||||||
run_without_connection do |orig_connection|
|
run_without_connection do |orig_connection|
|
||||||
ActiveRecord::Base.establish_connection(orig_connection.deep_merge({:variables => {:default_week_format => :default}}))
|
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
|
||||||
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
|
def test_mysql_set_session_variable_to_default
|
||||||
run_without_connection do |orig_connection|
|
run_without_connection do |orig_connection|
|
||||||
ActiveRecord::Base.establish_connection(orig_connection.deep_merge({:variables => {:default_week_format => :default}}))
|
ActiveRecord::Base.establish_connection(orig_connection.deep_merge({:variables => {:default_week_format => :default}}))
|
||||||
|
Loading…
Reference in New Issue
Block a user