Ott*_*tto 5 mysql stored-procedures ruby-on-rails
当我尝试从Rails调用存储过程时,我得到以下异常:
ActiveRecord::StatementInvalid: Mysql::Error: PROCEDURE pipeline-ws_development.match_save_all can't return a result set in the given context: call match_save_all()
from /Users/otto/Projects/Futures/src/pipeline-ws/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:150:in `log'
from /Users/otto/Projects/Futures/src/pipeline-ws/vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:281:in `execute'
from (irb):3
Run Code Online (Sandbox Code Playgroud)
Rails Wiki中有一个页面讨论了解决此问题的MySQL适配器的补丁,但它已经过时并且似乎不再起作用了.
配置代码正确地启用了存储过程,但是在存储过程调用之后连接失去同步仍然存在问题,并且新call_sp方法不再起作用.
有关如何使其工作的任何建议?
这是我正在使用的代码:
ActiveRecord::Base.connection("call storedproc()")
Run Code Online (Sandbox Code Playgroud)
无论是否storedproc()返回任何结果,它都会抛出相同的异常.
将过程包装在函数中可行吗?如果 Ruby 由于没有返回行而发生呕吐 ( ...can't return a result set in the given context...),这可能会修复它:
分隔符$
创建过程 tProc()
开始
SET @a = '测试';
结尾;
$
创建函数 tFunc()
返回整数
开始
调用 tProc();
返回1;
结尾;
$
分隔符;
从 DUAL 中选择 tFunc();
>> 1
从 DUAL 中选择@a;
>>“测试”
但实际上,这并不是一个可扩展的解决方案。
后续:我对 Ruby/ActiveRecord 很陌生,但这个例子绝对有效
ActiveRecord::Base.建立_连接(authopts)
类 TestClass < ActiveRecord::Base
结尾
test_class = TestClass.new
%{#{test_class.connection.select_one('SELECT tFunc() AS tf FROM DUAL')}}
>> tf1
使用CALL tProc()导致了与您类似的错误。
| 归档时间: |
|
| 查看次数: |
8274 次 |
| 最近记录: |