@H_403_1@当我尝试从Rails调用存储过程时,我得到以下异常:
@H_403_1@
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
@H_403_1@在Rails Wiki that discusses a patch中有一个用于解决此问题的MysqL适配器的页面,但它已经过时并且似乎不再起作用了.
@H_403_1@配置代码正确地启用了存储过程,但是在存储过程调用之后连接失去同步并且新的call_sp方法不再起作用仍然存在问题.
@H_403_1@有关如何使其工作的任何建议?
@H_403_1@这是我正在使用的代码:
@H_403_1@
ActiveRecord::Base.connection("call storedproc()")
@H_403_1@无论storedproc()是否返回任何结果,它都会抛出相同的异常.最佳答案
是否可以将过程包装在函数中?如果由于没有返回行而导致Ruby的barfing(…无法在给定的上下文中返回结果集…),这可能会解决它:
@H_403_1@
DELIMITER $ CREATE PROCEDURE tProc() BEGIN SET @a = 'test'; END; $ CREATE FUNCTION tFunc() RETURNS INT BEGIN CALL tProc(); RETURN 1; END; $ DELIMITER ; SELECT tFunc() FROM DUAL; >> 1 SELECT @a FROM DUAL; >> 'test'@H_403_1@虽然,实际上,这不是一个非常可扩展的解决方案. @H_403_1@后续:我非常熟悉Ruby / ActiveRecord,但这个例子绝对有效 @H_403_1@
ActiveRecord::Base.establish_connection(authopts) class TestClass < ActiveRecord::Base end test_class = TestClass.new puts %{#{test_class.connection.select_one('SELECT tFunc() AS tf FROM DUAL')}} >> tf1@H_403_1@使用CALL tProc()会导致类似于您的错误.