I am trying to use a store procedure from ruby, with Sequel gem; but it continues to throw me a Mysql2::Error: Commands out of sync; you can't run this command now after running a stored procedure, can't find anything about multi statements query on the docs:
MyModel.db['CALL get_info("arg")').first
# => {col: val, col2: val}
MyModel.db['CALL get_info("arg")').first
# => Sequel::DatabaseDisconnectError: Mysql2::Error: Commands out of sync; you can't run this command now
from /usr/local/lib/ruby/gems/2.3.0/gems/mysql2-0.4.5/lib/mysql2/client.rb:120:in `_query'
With the help of the creator of Sequel
gem I come up with a solution, it appears that Sequel does not support this kind of return set, so the mysql2 driver must be used:
res = nil
Domain.db.synchronize do |conn|
res = conn.query("CALL sp_panel_info('#{self.code}')")
while conn.next_result
conn.store_result
end
end
row = res.first
In this case I know for sure that my procedure will return one row so I only get the first one.