2010-09-28 40 views
1

我已经将ActiveRecord合并到脚本中,我正在编写处理MySQL数据库中的一些数据。在我的开发环境,使用Mac OS X,一切正常,但是,当我尝试部署在Linux环境中的脚本,我不断收到以下错误:ActiveRecord> MySQL适配器>未定义的方法`more_results'

/activerecord-3.0.0/lib/active_record/connection_adapters/mysql_adapter.rb:623:in `select': undefined method `more_results' for #<Mysql:0x915976c> (NoMethodError) 

哪里这个错误是发生的代码粘贴在下面,特别是已经评论的倒数第二行。

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 

为什么引入可以在https://rails.lighthouseapp.com/projects/8994/tickets/3151-mysql-adapter-update-to-enable-use-of-stored-procedures#ticket-3151-33

这就是说观看这段代码的历史,我仍然不确定如何不只是注释掉该问题的行修复此错误。我没有使用任何存储过程,所以它不是一个重要的问题,但是,我想实现一个更可扩展的修复程序。

我在两种环境中使用以下宝石。

的ActiveRecord(3.0.0) MySQL的(2.8.1)

预先感谢上可能被这里发生的任何想法!

回答

1

我是ruby(ha)的新手,在执行本教程时遇到了同样的问题:http://guides.rubyonrails.org/getting_started.html在执行6.1(迁移)期间。

我只是在包裹的命令,如果要确保该方法确实存在调用它,像这样前:

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 

当时我能够完成本教程就好了。我不知道跳过这行代码会有什么影响,但是在我的小开发箱中,这可能并不重要。