11155
(-- --)
1
Hi All,
Suppose I have a stored procedure named procedure().
Running ActiveRecord::Base.connection.execute("CALL procedure()") will
give you a bunch of errors in different cases while using mysql2 adapter
like:
ActiveRecord::StatementInvalid: Mysql2::Error: PROCEDURE can't return a
result set in the given context: procedure() PROCEDURE
or
ActiveRecord::StatementInvalid: Mysql2::Error: Commands out of sync; you
can't run this command now.
How can The problem be solved? Need Assistance.
Best Regards,
Nirmalya Ghosh
11155
(-- --)
2
Hello Nirmalya,
It's a very important question which you have right now, fortunately I
think I know the answer, here I am giving you the solution ---
Solution :
When MySQL runs stored procedure it has to know that client can handle
multiple result sets.
We will create patch file for that in our initializer folder of our
application.
Create mysql2_adapter.rb file in config/initializers with the following
content:
module ActiveRecord
class Base
# Overriding ActiveRecord::Base.mysql2_connection
# method to allow passing options from database.yml
11155
(-- --)
3
Thanks Zinia for the reply and I think I got the answer.
Thanks Again.
Best Regards,
Nirmalya Ghosh
Zinia Dutta Gupta wrote in post #1141735: