1. <small id='QIwqK'></small><noframes id='QIwqK'>

      <bdo id='QIwqK'></bdo><ul id='QIwqK'></ul>

    <tfoot id='QIwqK'></tfoot>
    1. <legend id='QIwqK'><style id='QIwqK'><dir id='QIwqK'><q id='QIwqK'></q></dir></style></legend>
      <i id='QIwqK'><tr id='QIwqK'><dt id='QIwqK'><q id='QIwqK'><span id='QIwqK'><b id='QIwqK'><form id='QIwqK'><ins id='QIwqK'></ins><ul id='QIwqK'></ul><sub id='QIwqK'></sub></form><legend id='QIwqK'></legend><bdo id='QIwqK'><pre id='QIwqK'><center id='QIwqK'></center></pre></bdo></b><th id='QIwqK'></th></span></q></dt></tr></i><div id='QIwqK'><tfoot id='QIwqK'></tfoot><dl id='QIwqK'><fieldset id='QIwqK'></fieldset></dl></div>

      是否可以从 Ruby 调用 MySQL 存储过程?

      Is it possible to call a MySQL stored procedure from Ruby?(是否可以从 Ruby 调用 MySQL 存储过程?)
      • <legend id='r43zR'><style id='r43zR'><dir id='r43zR'><q id='r43zR'></q></dir></style></legend>
          <bdo id='r43zR'></bdo><ul id='r43zR'></ul>
          <tfoot id='r43zR'></tfoot>

        • <i id='r43zR'><tr id='r43zR'><dt id='r43zR'><q id='r43zR'><span id='r43zR'><b id='r43zR'><form id='r43zR'><ins id='r43zR'></ins><ul id='r43zR'></ul><sub id='r43zR'></sub></form><legend id='r43zR'></legend><bdo id='r43zR'><pre id='r43zR'><center id='r43zR'></center></pre></bdo></b><th id='r43zR'></th></span></q></dt></tr></i><div id='r43zR'><tfoot id='r43zR'></tfoot><dl id='r43zR'><fieldset id='r43zR'></fieldset></dl></div>
              <tbody id='r43zR'></tbody>

            <small id='r43zR'></small><noframes id='r43zR'>

                本文介绍了是否可以从 Ruby 调用 MySQL 存储过程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                当我尝试从 Rails 调用存储过程时,出现此异常:

                ActiveRecord::StatementInvalid: Mysql::Error: PROCEDURE pipeline-ws_development.match_save_all 无法返回给定上下文中的结果集:调用 match_save_all()来自/Users/otto/Projects/Futures/src/pipeline-ws/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:150:in `log'来自/Users/otto/Projects/Futures/src/pipeline-ws/vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:281:in `execute'来自 (irb):3

                Rails Wiki 中有一个页面讨论了 MySQL 的补丁解决此问题的适配器,但它已过时且似乎不再起作用.

                配置代码正确启用存储过程,但仍然存在连接在存储过程调用后不同步的问题,并且新的 call_sp 方法不再起作用.

                有关如何使其工作的任何建议?

                这是我正在使用的代码:

                ActiveRecord::Base.connection("调用storedproc()")

                无论 storedproc() 是否返回任何结果,它都会抛出相同的异常.

                解决方案

                将过程包装在一个函数中是否可行?如果 Ruby 因没有返回行而导致呕吐(...无法在给定的上下文中返回结果集...),这可能会解决它:

                <前>分隔符 $创建过程 tProc()开始SET @a = '测试';结尾;$创建函数 tFunc()退货积分开始调用 tProc();返回 1;结尾;$分隔符;从 DUAL 中选择 tFunc();>> 1从双重选择@a;>> '测试'

                虽然,实际上,这不是一个非常可扩展的解决方案.

                跟进:我在 Ruby/ActiveRecord 方面很不擅长,但这个例子绝对有效

                <前>ActiveRecord::Base.establish_connection(authopts)类 TestClass

                使用 CALL tProc() 会导致与您类似的错误.

                When I try to call a stored procedure from Rails, I get this exception:

                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
                

                There is a page in the Rails Wiki that discusses a patch for the MySQL adapter that resolves this issue, but it's out-of-date and doesn't seem to work anymore.

                The configuration code enables stored procedures correctly, but it still has the issue with the connection getting out of sync after a stored procedure call and the new call_sp method doesn't work anymore.

                Any suggestions for how to get this working?

                This is the code I'm using:

                ActiveRecord::Base.connection("call storedproc()")
                

                It throws the same exception whether storedproc() returns any results or not.

                解决方案

                Would it work to wrap the procedure in a function? If Ruby's barfing due to no rows returned (...can't return a result set in the given context...), this may fix it:

                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'
                

                Although, realistically, this isn't a very extensible solution.

                Followup: I'm pretty n00by at Ruby/ActiveRecord, but this example definitely works

                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
                

                Using CALL tProc() resulted in an error similar to yours.

                这篇关于是否可以从 Ruby 调用 MySQL 存储过程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Accessing another user#39;s table within an Oracle Stored Procedure(在 Oracle 存储过程中访问另一个用户的表)
                Maximum stored procedure, function, trigger, or view nesting level exceeded (limit 32)(超出最大存储过程、函数、触发器或视图嵌套级别(限制 32))
                How to View Oracle Stored Procedure using SQLPlus?(如何使用 SQLPlus 查看 Oracle 存储过程?)
                How to Pass Java List of Objects to Oracle Stored Procedure Using MyBatis?(如何使用 MyBatis 将 Java 对象列表传递给 Oracle 存储过程?)
                Set the variable result, from query(设置变量结果,来自查询)
                What is dynamic SQL?(什么是动态 SQL?)

                • <bdo id='QqIjF'></bdo><ul id='QqIjF'></ul>

                      <tbody id='QqIjF'></tbody>

                    <i id='QqIjF'><tr id='QqIjF'><dt id='QqIjF'><q id='QqIjF'><span id='QqIjF'><b id='QqIjF'><form id='QqIjF'><ins id='QqIjF'></ins><ul id='QqIjF'></ul><sub id='QqIjF'></sub></form><legend id='QqIjF'></legend><bdo id='QqIjF'><pre id='QqIjF'><center id='QqIjF'></center></pre></bdo></b><th id='QqIjF'></th></span></q></dt></tr></i><div id='QqIjF'><tfoot id='QqIjF'></tfoot><dl id='QqIjF'><fieldset id='QqIjF'></fieldset></dl></div>

                    1. <small id='QqIjF'></small><noframes id='QqIjF'>

                      <tfoot id='QqIjF'></tfoot>

                      <legend id='QqIjF'><style id='QqIjF'><dir id='QqIjF'><q id='QqIjF'></q></dir></style></legend>