提交 d5be4f1a 编写于 作者: R Ryuta Kamizono

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
上级 a3f4a62e
......@@ -97,39 +97,27 @@ def last_inserted_id(result)
@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 @@ def test_bulk_insert_with_multi_statements_enabled
]
}
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 @@ def test_bulk_insert_with_multi_statements_enabled
end
end
end
end
def test_bulk_insert_with_multi_statements_disabled
run_without_connection do |orig_connection|
......@@ -184,7 +182,6 @@ def test_bulk_insert_with_multi_statements_disabled
]
}
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 @@ def test_bulk_insert_with_multi_statements_disabled
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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册