Skip to content

Commit

Permalink
Make mysql2 adapter handle invalid statement handles when closing pre…
Browse files Browse the repository at this point in the history
…pared statements

While here, fix a verbose warning in the previous commit.
  • Loading branch information
jeremyevans committed Jan 20, 2025
1 parent f9b3a74 commit 7787520
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
=== master

* Make mysql2 adapter handle invalid statement handles when closing prepared statements (jeremyevans)

* Add query_blocker extension, for blocking queries inside a block (jeremyevans)

* Support alter_table add_primary_key/add_unique_constraint :using_index option on PostgreSQL 9.1+ (jeremyevans)
Expand Down
9 changes: 8 additions & 1 deletion lib/sequel/adapters/mysql2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,14 @@ def execute_prepared_statement(ps_name, opts, &block)
synchronize(opts[:server]) do |conn|
stmt, ps_sql = conn.prepared_statements[ps_name]
unless ps_sql == sql
stmt.close if stmt
if stmt
begin
stmt.close
rescue ::Mysql2::Error
# probably Invalid statement handle, can happen from dropping
# related table, ignore as we won't be using it again.
end
end
stmt = log_connection_yield("Preparing #{ps_name}: #{sql}", conn){conn.prepare(sql)}
conn.prepared_statements[ps_name] = [stmt, sql]
end
Expand Down
2 changes: 1 addition & 1 deletion spec/integration/plugin_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3239,7 +3239,7 @@ def set(k, v, ttl) self[k] = v end
@db.drop_table?(:query_blocker_test)
end

types = {
{
"SELECT" => proc{@ds.all},
"INSERT" => proc{@ds.insert(1)},
"UPDATE" => proc{@ds.update(:i => 1)},
Expand Down

0 comments on commit 7787520

Please sign in to comment.