How can I iterate through a MySQL result set?

前端 未结 4 1800
轻奢々
轻奢々 2020-12-10 02:41

Here is the code I\'m using:

# Run the query against the database defined in .yml file.
# This is a Mysql::result object - http://www.tmtm.org/en/mysql/ruby/         


        
4条回答
  •  温柔的废话
    2020-12-10 03:28

    Use :as => :hash:

    raw = ActiveRecord::Base.connection.execute(sql)
    raw.each(:as => :hash) do |row|
      puts row.inspect # row is hash
    end
    

提交回复
热议问题