Created a simple stored procedure in MySQL:
CREATE PROCEDURE `proc01`()
BEGIN
SELECT * FROM users;
END
Start Rails console:
$ script/console
Loading development environment (Rails 2.3.5)
>> User.connection.execute("CALL proc01")
=> #<Mysql::Result:0x10343efa0>
Looks good. BUT, any more call to the same stored procedure via the existing connection will result in an Commands out of sync error:
>> User.connection.execute("CALL proc01")
ActiveRecord::StatementInvalid: Mysql::Error: Commands out of sync; you can't run this command now: CALL proc01
from /Library/Ruby/Gems/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapters/abstract_adapter.rb:219:in `log'
from /Library/Ruby/Gems/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapters/mysql_adapter.rb:323:in `execute'
from (irb):2
The error can be cleared by a "reload!" command in the console:
>> reload!
Reloading...
=> true
>> User.connection.execute("CALL proc01")
=> #<Mysql::Result:0x1033f14d0>
>>
How can I call MySQL stored procedure from Rails? Thanks~