mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
If specify strict: :default
explicitly, do not set sql_mode.
Related with #17370.
This commit is contained in:
parent
8887449354
commit
7961f4f776
3 changed files with 22 additions and 2 deletions
|
@ -959,10 +959,12 @@ module ActiveRecord
|
||||||
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)
|
||||||
|
|
||||||
|
defaults = [':default', :default].to_set
|
||||||
|
|
||||||
# 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.6/en/sql-mode.html#sqlmode_strict_all_tables
|
# http://dev.mysql.com/doc/refman/5.6/en/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.
|
||||||
unless variables.has_key?('sql_mode')
|
unless variables.has_key?('sql_mode') || defaults.include?(@config[:strict])
|
||||||
variables['sql_mode'] = strict_mode? ? 'STRICT_ALL_TABLES' : ''
|
variables['sql_mode'] = strict_mode? ? 'STRICT_ALL_TABLES' : ''
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -977,7 +979,7 @@ module ActiveRecord
|
||||||
|
|
||||||
# Gather up all of the SET variables...
|
# Gather up all of the SET variables...
|
||||||
variable_assignments = variables.map do |k, v|
|
variable_assignments = variables.map do |k, v|
|
||||||
if v == ':default' || v == :default
|
if defaults.include?(v)
|
||||||
"@@SESSION.#{k} = DEFAULT" # Sets the value to the global or compile default
|
"@@SESSION.#{k} = DEFAULT" # Sets the value to the global or compile default
|
||||||
elsif !v.nil?
|
elsif !v.nil?
|
||||||
"@@SESSION.#{k} = #{quote(v)}"
|
"@@SESSION.#{k} = #{quote(v)}"
|
||||||
|
|
|
@ -145,6 +145,15 @@ class MysqlConnectionTest < ActiveRecord::TestCase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_mysql_strict_mode_specified_default
|
||||||
|
run_without_connection do |orig_connection|
|
||||||
|
ActiveRecord::Base.establish_connection(orig_connection.merge({strict: :default}))
|
||||||
|
global_sql_mode = ActiveRecord::Base.connection.exec_query "SELECT @@GLOBAL.sql_mode"
|
||||||
|
session_sql_mode = ActiveRecord::Base.connection.exec_query "SELECT @@SESSION.sql_mode"
|
||||||
|
assert_equal global_sql_mode.rows, session_sql_mode.rows
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_mysql_set_session_variable
|
def test_mysql_set_session_variable
|
||||||
run_without_connection do |orig_connection|
|
run_without_connection do |orig_connection|
|
||||||
ActiveRecord::Base.establish_connection(orig_connection.deep_merge({:variables => {:default_week_format => 3}}))
|
ActiveRecord::Base.establish_connection(orig_connection.deep_merge({:variables => {:default_week_format => 3}}))
|
||||||
|
|
|
@ -84,6 +84,15 @@ class MysqlConnectionTest < ActiveRecord::TestCase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_mysql_strict_mode_specified_default
|
||||||
|
run_without_connection do |orig_connection|
|
||||||
|
ActiveRecord::Base.establish_connection(orig_connection.merge({strict: :default}))
|
||||||
|
global_sql_mode = ActiveRecord::Base.connection.exec_query "SELECT @@GLOBAL.sql_mode"
|
||||||
|
session_sql_mode = ActiveRecord::Base.connection.exec_query "SELECT @@SESSION.sql_mode"
|
||||||
|
assert_equal global_sql_mode.rows, session_sql_mode.rows
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_mysql_set_session_variable
|
def test_mysql_set_session_variable
|
||||||
run_without_connection do |orig_connection|
|
run_without_connection do |orig_connection|
|
||||||
ActiveRecord::Base.establish_connection(orig_connection.deep_merge({:variables => {:default_week_format => 3}}))
|
ActiveRecord::Base.establish_connection(orig_connection.deep_merge({:variables => {:default_week_format => 3}}))
|
||||||
|
|
Loading…
Reference in a new issue