diff options
author | Rafael França <rafaelmfranca@gmail.com> | 2018-07-18 16:53:52 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-18 16:53:52 -0400 |
commit | 371e3752948a324da70dc8fc8b0a2f2c66113112 (patch) | |
tree | b9e8f0eca80d7ca4081a34bac5dcb1852918610e /activerecord/lib | |
parent | dc1c679d897281e92eef9f7540e540eb6334f94c (diff) | |
parent | 425449e98d0539e3fa4debb819283103cf27bce5 (diff) | |
download | rails-371e3752948a324da70dc8fc8b0a2f2c66113112.tar.gz rails-371e3752948a324da70dc8fc8b0a2f2c66113112.tar.bz2 rails-371e3752948a324da70dc8fc8b0a2f2c66113112.zip |
Merge pull request #33363 from ahorek/transaction_bug
use set_server_option if possible
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb index 07acb5425e..07206f0d01 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb @@ -559,14 +559,32 @@ module ActiveRecord end def with_multi_statements - previous_flags = @config[:flags] - @config[:flags] = Mysql2::Client::MULTI_STATEMENTS - reconnect! + if supports_set_server_option? + @connection.set_server_option(Mysql2::Client::OPTION_MULTI_STATEMENTS_ON) + elsif !supports_multi_statements? + previous_flags = @config[:flags] + @config[:flags] = Mysql2::Client::MULTI_STATEMENTS + reconnect! + end yield ensure - @config[:flags] = previous_flags - reconnect! + unless supports_multi_statements? + if supports_set_server_option? + @connection.set_server_option(Mysql2::Client::OPTION_MULTI_STATEMENTS_OFF) + else + @config[:flags] = previous_flags + reconnect! + end + end + end + + def supports_multi_statements? + (@config[:flags] & Mysql2::Client::MULTI_STATEMENTS) != 0 + end + + def supports_set_server_option? + @connection.respond_to?(:set_server_option) end def initialize_type_map(m = type_map) |