如何使用 Sequel 的存储过程

How to use stored procedures with Sequel

我正在尝试使用 ruby 中的存储过程和 Sequel gem;但它继续给我一个Mysql2::Error:命令不同步;你现在不能 运行 这个命令 在 运行 存储过程之后,在文档上找不到任何关于多语句查询的信息:

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'

Sequelgem的创建者的帮助下,我想出了一个解决方案,Sequel似乎不​​支持这种return设置,所以必须使用 mysql2 驱动程序:

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

在这种情况下,我确定我的程序会 return 一行,所以我只得到第一行。