【发布时间】:2015-11-15 06:20:27
【问题描述】:
我在 Rails 中直接使用 Model.connection 运行 MySQL 存储过程。所有数据都正确插入数据库并按预期返回,但我在测试中收到以下错误:
ActiveRecord::StatementInvalid: Mysql2::Error: 命令不同步;您现在无法运行此命令:ROLLBACK
ActiveRecord::StatementInvalid: Mysql2::Error: 命令不同步;您现在无法运行此命令:BEGIN
暂定1:
Model.connection.transaction do
result = Model.connection.select_value("CALL myStoredProcedure(...);")
end
暂定2:
Model.connection.begin_db_transaction
result = Model.connection.select_value("CALL myStoredProcedure(...);")
Model.connection.commit_db_transaction
暂定3:
result = Model.connection.select_value("CALL myStoredProcedure(...);")
Model.clear_active_connections!
Tentative #3 导致“ActiveRecord::StatementInvalid: Mysql2::Error: Commands out of sync; you can't run this command now: BEGIN”消失。 ROLLBACK 命令的错误仍然存在。
我做错了什么?
谢谢
【问题讨论】:
标签: mysql ruby-on-rails ruby activerecord