Skip to content

Commit a7df5af

Browse files
committed
If specify strict: :default explicitly, do not set sql_mode.
1 parent c184f1e commit a7df5af

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,7 @@ def configure_connection
810810
# Make MySQL reject illegal values rather than truncating or blanking them, see
811811
# http://dev.mysql.com/doc/refman/5.0/en/server-sql-mode.html#sqlmode_strict_all_tables
812812
# If the user has provided another value for sql_mode, don't replace it.
813-
if @config.has_key?(:strict) && !variables.has_key?('sql_mode')
813+
unless [':default', :default].include?(@config[:strict]) || variables.has_key?('sql_mode')
814814
variables['sql_mode'] = strict_mode? ? 'STRICT_ALL_TABLES' : ''
815815
end
816816

activerecord/test/cases/adapters/mysql/connection_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,9 @@ def test_mysql_strict_mode_disabled
147147
end
148148
end
149149

150-
def test_mysql_strict_mode_unspecified
150+
def test_mysql_strict_mode_specified_default
151151
run_without_connection do |orig_connection|
152-
ActiveRecord::Base.establish_connection(orig_connection.reject{|key, _| key == :strict})
152+
ActiveRecord::Base.establish_connection(orig_connection.merge({strict: :default}))
153153
global_sql_mode = ActiveRecord::Base.connection.exec_query "SELECT @@GLOBAL.sql_mode"
154154
session_sql_mode = ActiveRecord::Base.connection.exec_query "SELECT @@SESSION.sql_mode"
155155
assert_equal global_sql_mode.rows, session_sql_mode.rows

activerecord/test/cases/adapters/mysql2/connection_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ def test_mysql_strict_mode_disabled
8686
end
8787
end
8888

89-
def test_mysql_strict_mode_unspecified
89+
def test_mysql_strict_mode_specified_default
9090
run_without_connection do |orig_connection|
91-
ActiveRecord::Base.establish_connection(orig_connection.reject{|key, _| key == :strict})
91+
ActiveRecord::Base.establish_connection(orig_connection.merge({strict: :default}))
9292
global_sql_mode = ActiveRecord::Base.connection.exec_query "SELECT @@GLOBAL.sql_mode"
9393
session_sql_mode = ActiveRecord::Base.connection.exec_query "SELECT @@SESSION.sql_mode"
9494
assert_equal global_sql_mode.rows, session_sql_mode.rows

0 commit comments

Comments
 (0)