How to write stored procedure in rails 3
Writing Stored procedure in rails 3
Now using Mysql2 gem writing stored procedure is pretty much easy. Just we need to follow the below steps to write stored procedure in ORM.
1) Connect the database.
client = Mysql2::Client.new(:host => "localhost", :username => "root", :database => "XXX", :password => "XYZ", :flags => Mysql2::Client::MULTI_STATEMENTS )
This extra flag option is most important and multiple result sets is normally used when calling stored procedures that return more than one result set.
2) Fetch the data.
result = client.query( 'CALL sp_test');
It will return the Result set.
Now result contains first result set and to fetch the Next result set we need to follow the next step
While (client.next_result)
result = client.store_result #To get the next result set
end
good work.. really helpful
ReplyDeleteThanks :)
ReplyDeleteits great .. really too good
ReplyDeleteThanks Soutom :)
ReplyDeleteNice work :) .. and well researched.
ReplyDelete