Skip to content

Commit 4ff28e8

Browse files
committed
Always discard mysql2 multi-statement results
Same as Trilogy, using abandon_results! needs to be done on the same original connection, and the best way to do that is inside raw_execute.
1 parent 86f0259 commit 4ff28e8

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

activerecord/lib/active_record/connection_adapters/mysql2/database_statements.rb

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,11 @@ module Mysql2
66
module DatabaseStatements
77
# Returns an ActiveRecord::Result instance.
88
def select_all(*, **) # :nodoc:
9-
result = nil
10-
with_raw_connection do |conn|
11-
result = if ExplainRegistry.collect? && prepared_statements
12-
unprepared_statement { super }
13-
else
14-
super
15-
end
16-
conn.abandon_results!
9+
if ExplainRegistry.collect? && prepared_statements
10+
unprepared_statement { super }
11+
else
12+
super
1713
end
18-
result
1914
end
2015

2116
def internal_exec_query(sql, name = "SQL", binds = [], prepare: false, async: false, allow_retry: false) # :nodoc:
@@ -60,7 +55,6 @@ def execute_batch(statements, name = nil)
6055
combine_multi_statements(statements).each do |statement|
6156
with_raw_connection do |conn|
6257
raw_execute(statement, name)
63-
conn.abandon_results!
6458
end
6559
end
6660
end
@@ -102,6 +96,7 @@ def raw_execute(sql, name, async: false, allow_retry: false, materialize_transac
10296
with_raw_connection(allow_retry: allow_retry, materialize_transactions: materialize_transactions) do |conn|
10397
sync_timezone_changes(conn)
10498
result = conn.query(sql)
99+
conn.abandon_results!
105100
verified!
106101
handle_warnings(sql)
107102
notification_payload[:row_count] = result&.size || 0

0 commit comments

Comments
 (0)