如何从gem-mysql2获取查询结果?

时间:2018-03-23 15:22:16

标签: mysql ruby

为什么我在执行以下操作时无法获得选择查询的结果?

#!/usr/bin/ruby

require 'mysql2'
require 'awesome_print'

client = Mysql2::Client.new(:host => "example.com", :username => "x", :password => "x", :database => "hd")

r = client.query("select CLIENT_ID from CLIENT where EMAIL='x@x.com'")

ap r

输出

$ ./hd.rb 
/usr/share/gems/gems/awesome_print-1.0.2/lib/awesome_print/formatter.rb:355: warning: constant ::Fixnum is deprecated
#<Mysql2::Result:0x55fab9bfd880
    @query_options = {
                          :as => :hash,
                       :async => false,
               :cast_booleans => false,
              :symbolize_keys => false,
           :database_timezone => :local,
        :application_timezone => nil,
                  :cache_rows => true,
               :connect_flags => 2147525124,
                        :cast => true,
                :default_file => nil,
               :default_group => nil,
                        :host => "example.com",
                    :username => "x",
                    :password => "x",
                    :database => "hd"
    }

0 个答案:

没有答案