aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2018-07-19 11:25:08 +0900
committerRyuta Kamizono <kamipo@gmail.com>2018-07-19 11:35:57 +0900
commit9fc728cf09adf318bf58c59b7f4ca41f57a6f6b1 (patch)
tree51407f1f4cd40fd8be8547ce5cbfa49a5a550617 /activerecord/lib
parent3ccec9b80d8ba83bfddf0d4bf5df82cd59bfc73a (diff)
downloadrails-9fc728cf09adf318bf58c59b7f4ca41f57a6f6b1.tar.gz
rails-9fc728cf09adf318bf58c59b7f4ca41f57a6f6b1.tar.bz2
rails-9fc728cf09adf318bf58c59b7f4ca41f57a6f6b1.zip
Fix `insert_fixtures_set` to be restored original connection flags
#33363 has two regressions. First one is that `insert_fixtures_set` is failed if flags is an array. Second one is that connection flags are not restored if `set_server_option` is not supported.
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb29
-rw-r--r--activerecord/lib/active_record/connection_adapters/mysql/database_statements.rb36
2 files changed, 36 insertions, 29 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 07206f0d01..284b38ed7b 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
@@ -558,35 +558,6 @@ module ActiveRecord
@max_allowed_packet ||= (show_variable("max_allowed_packet") - bytes_margin)
end
- def with_multi_statements
- 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
- 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)
super
diff --git a/activerecord/lib/active_record/connection_adapters/mysql/database_statements.rb b/activerecord/lib/active_record/connection_adapters/mysql/database_statements.rb
index 4106ce01be..d89eeb7f54 100644
--- a/activerecord/lib/active_record/connection_adapters/mysql/database_statements.rb
+++ b/activerecord/lib/active_record/connection_adapters/mysql/database_statements.rb
@@ -62,6 +62,42 @@ module ActiveRecord
@connection.abandon_results!
end
+ def supports_set_server_option?
+ @connection.respond_to?(:set_server_option)
+ end
+
+ def multi_statements_enabled?(flags)
+ if flags.is_a?(Array)
+ flags.include?("MULTI_STATEMENTS")
+ else
+ (flags & Mysql2::Client::MULTI_STATEMENTS) != 0
+ end
+ end
+
+ def with_multi_statements
+ previous_flags = @config[:flags]
+
+ unless multi_statements_enabled?(previous_flags)
+ if supports_set_server_option?
+ @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?
+ @connection.set_server_option(Mysql2::Client::OPTION_MULTI_STATEMENTS_OFF)
+ else
+ @config[:flags] = previous_flags
+ reconnect!
+ end
+ end
+ end
+
def exec_stmt_and_free(sql, name, binds, cache_stmt: false)
# make sure we carry over any changes to ActiveRecord::Base.default_timezone that have been
# made since we established the connection