[英]ActiveRecord > MySQL Adapter > undefined method `more_results'
I have incorporated ActiveRecord into a script I am writing to process some data in a MySQL database. 我已经将ActiveRecord合并到我正在编写的脚本中,以处理MySQL数据库中的某些数据。 In my development environment, using Mac OS X, everything works fine, however, when I attempt to deploy the script in a Linux environment, I keep getting the following error:
在我的开发环境中,使用Mac OS X,一切正常,但是,当我尝试在Linux环境中部署脚本时,始终出现以下错误:
/activerecord-3.0.0/lib/active_record/connection_adapters/mysql_adapter.rb:623:in `select': undefined method `more_results' for #<Mysql:0x915976c> (NoMethodError)
The code where this error is occuring is pasted below, specifically the second to last line that has been commented. 发生此错误的代码粘贴在下面,特别是已注释的倒数第二行。
def select(sql, name = nil)
@connection.query_with_result = true
result = execute(sql, name)
rows = []
result.each_hash { |row| rows << row }
result.free
@connection.more_results && @connection.next_result # invoking stored procedures with CLIENT_MULTI_RESULTS requires this to tidy up else connection will be dropped
rows
end
The history of why this code was introduced can be viewed at https://rails.lighthouseapp.com/projects/8994/tickets/3151-mysql-adapter-update-to-enable-use-of-stored-procedures#ticket-3151-33 可以在https://rails.lighthouseapp.com/projects/8994/tickets/3151-mysql-adapter-update-to-enable-use-of-stored-procedures#ticket-中查看引入此代码的历史。 3151-33
That said, I am still uncertain how to fix this error without just commenting out that problematic line. 就是说,我仍然不确定如何解决此错误,而不必仅注释掉有问题的行。 I am not using any stored procedures so it is not a significant issue, however, I would like to implement a more extensible fix.
我没有使用任何存储过程,因此这不是一个重要的问题,但是,我想实施一个更可扩展的修复程序。
I am using the following gems in both environments. 我在两种环境中都使用以下宝石。
activerecord (3.0.0) mysql (2.8.1) activerecord(3.0.0)MySQL(2.8.1)
Thanks in advance for any thoughts on what might be going on here! 预先感谢您对这里可能发生的任何想法!
I'm a newbie to Ruby (ha), and I ran into the same problem while going through this tutorial: http://guides.rubyonrails.org/getting_started.html during step 6.1 (migrate). 我是Ruby(ha)的新手,在学习本教程时遇到了相同的问题:在步骤6.1(迁移)中, http : //guides.rubyonrails.org/getting_started.html 。
I simply wrapped the command in an if to ensure the method actually exists before calling it, like so: 我只是将命令包装在if中,以确保在调用该方法之前该方法确实存在,如下所示:
if (@connection.respond_to?('more_results'))
@connection.more_results && @connection.next_result # invoking stored procedures with CLIENT_MULTI_RESULTS requires this to tidy up else connection will be dropped
end
I was then able to complete the tutorial just fine. 然后,我就可以顺利完成本教程。 I don't know what the implications are in skipping that line of code, but on my little development box, it probably doesn't matter.
我不知道跳过那行代码的含义是什么,但是在我的小开发盒中,这可能并不重要。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.