aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorpavel <pavel.rosicky@easy.cz>2018-07-15 05:11:16 +0200
committerpavel <pavel.rosicky@easy.cz>2018-07-15 06:09:43 +0200
commit425449e98d0539e3fa4debb819283103cf27bce5 (patch)
tree12db31c9a6df50a27e5ceccd45ab66729f792219 /activerecord/lib
parent05bef140519fe3410fd8d352f5ea84fd1a278063 (diff)
downloadrails-425449e98d0539e3fa4debb819283103cf27bce5.tar.gz
rails-425449e98d0539e3fa4debb819283103cf27bce5.tar.bz2
rails-425449e98d0539e3fa4debb819283103cf27bce5.zip
use set_server_option if possible
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb28
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)