简体   繁体   中英

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. 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:

/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

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)

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).

I simply wrapped the command in an if to ensure the method actually exists before calling it, like so:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM