0

I am calling a stored procedure that returns several results.

In Rails 4, the only solution found is to initiate a new Mysql2::Client with the flag MULTI_STATEMENTS. It seems not right to me to open a new connection to the database server.

options = Rails.application.config_for(:database).merge flags: Mysql2::Client::MULTI_STATEMENTS
client = Mysql2::Client.new options
results = client.query %Q{CALL my_proc('#{params}')}
client.close

results

So my question: is there a better solution as of now?

2

1 Answer 1

0

The solution is to call the stored proc with exec_query then to clear_active_connections! like this:

results = ActiveRecord::Base.connection.exec_query %Q{CALL my_proc('#{params}')}
ActiveRecord::Base.clear_active_connections!

results

Not the answer you're looking for? Browse other questions tagged or ask your own question.