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:
Rafael Mendonça França 2014-05-01 17:49:20 -03:00
commit e99e23d115
4 changed files with 30 additions and 5 deletions

@ -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.
Fixes: #13631

@ -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}}))