Always respond to `set_server_option` since mysql2 0.5.0
https://github.com/brianmario/mysql2/pull/943 https://github.com/rails/rails/pull/37191
This commit is contained in:
parent
a3f4a62e2c
commit
d5be4f1a46
|
@ -97,39 +97,27 @@ module ActiveRecord
|
|||
@connection.last_id
|
||||
end
|
||||
|
||||
def supports_set_server_option?
|
||||
@connection.respond_to?(:set_server_option)
|
||||
end
|
||||
def multi_statements_enabled?
|
||||
flags = @config[:flags]
|
||||
|
||||
def multi_statements_enabled?(flags)
|
||||
if flags.is_a?(Array)
|
||||
flags.include?("MULTI_STATEMENTS")
|
||||
else
|
||||
(flags & Mysql2::Client::MULTI_STATEMENTS) != 0
|
||||
flags.anybits?(Mysql2::Client::MULTI_STATEMENTS)
|
||||
end
|
||||
end
|
||||
|
||||
def with_multi_statements
|
||||
previous_flags = @config[:flags]
|
||||
multi_statements_was = multi_statements_enabled?
|
||||
|
||||
unless multi_statements_enabled?(previous_flags)
|
||||
if supports_set_server_option?
|
||||
unless multi_statements_was
|
||||
@connection.set_server_option(Mysql2::Client::OPTION_MULTI_STATEMENTS_ON)
|
||||
else
|
||||
@config[:flags] = Mysql2::Client::MULTI_STATEMENTS
|
||||
reconnect!
|
||||
end
|
||||
end
|
||||
|
||||
yield
|
||||
ensure
|
||||
unless multi_statements_enabled?(previous_flags)
|
||||
if supports_set_server_option?
|
||||
unless multi_statements_was
|
||||
@connection.set_server_option(Mysql2::Client::OPTION_MULTI_STATEMENTS_OFF)
|
||||
else
|
||||
@config[:flags] = previous_flags
|
||||
reconnect!
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -147,7 +147,6 @@ class FixturesTest < ActiveRecord::TestCase
|
|||
]
|
||||
}
|
||||
|
||||
ActiveRecord::Base.connection.stub(:supports_set_server_option?, false) do
|
||||
assert_nothing_raised do
|
||||
conn = ActiveRecord::Base.connection
|
||||
conn.execute("SELECT 1; SELECT 2;")
|
||||
|
@ -170,7 +169,6 @@ class FixturesTest < ActiveRecord::TestCase
|
|||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_bulk_insert_with_multi_statements_disabled
|
||||
run_without_connection do |orig_connection|
|
||||
|
@ -184,7 +182,6 @@ class FixturesTest < ActiveRecord::TestCase
|
|||
]
|
||||
}
|
||||
|
||||
ActiveRecord::Base.connection.stub(:supports_set_server_option?, false) do
|
||||
assert_raises(ActiveRecord::StatementInvalid) do
|
||||
conn = ActiveRecord::Base.connection
|
||||
conn.execute("SELECT 1; SELECT 2;")
|
||||
|
@ -203,7 +200,6 @@ class FixturesTest < ActiveRecord::TestCase
|
|||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_insert_fixtures_set_raises_an_error_when_max_allowed_packet_is_smaller_than_fixtures_set_size
|
||||
conn = ActiveRecord::Base.connection
|
||||
|
|
Loading…
Reference in New Issue