Skip to content

Commit 5f14ba8

Browse files
authored
Merge pull request rails#53692 from byroot/fix-mysql2-prepared-statements
Fix Mysql2Adapter support for prepared statements
2 parents 5287cfa + ecbdbbf commit 5f14ba8

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,16 @@ def perform_query(raw_connection, sql, binds, type_casted_binds, prepare:, notif
5353

5454
begin
5555
ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
56-
stmt.execute(*type_casted_binds)
56+
result = stmt.execute(*type_casted_binds)
5757
end
5858
rescue ::Mysql2::Error
5959
@statements.delete(sql)
6060
stmt.close
6161
raise
6262
end
6363
verified!
64+
65+
result
6466
else
6567
raw_connection.query(sql)
6668
end

activerecord/test/cases/adapters/mysql2/mysql2_adapter_test.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ def close
6868
assert_equal false, adapter.prepared_statements
6969
end
7070

71+
def test_exec_query_with_prepared_statements
72+
result = @conn.exec_query("SELECT 1", "SQL", [], prepare: true)
73+
assert_equal [{ "1" => 1 }], result.to_a
74+
end
75+
7176
def test_exec_query_nothing_raises_with_no_result_queries
7277
assert_nothing_raised do
7378
with_example_table do

0 commit comments

Comments
 (0)