Null pointer given - hash

each and fetch hash doesn’t work, result showing: ‘fetch_hash’: NULL pointer given (Argument error). Only res.each works.

while row = res.fetch_hash do
  printf "%s, %s\n", row["name"], row["category"]
end
puts "Number of rows returned: #{res.num_rows}"

or

res.each_hash do |row|
  printf "%s, %s\n", row["name"], row["category"]
end

Thanks in advance

Angelo

Angelo Farias wrote in post #1021017:

each and fetch hash doesn’t work

They work fine:

hash = {'a' => 10, 'b' => 20}

hash.each do |key, val|
  puts "#{key} = #{val}"
end

--output:--
a = 10
b = 20

puts hash.fetch('c', "sorry")

--output:--
sorry

···

--
Posted via http://www.ruby-forum.com/\.

I mean res.each_hash and res.fetch_hash mysql, not hash method.

-----Mensagem Original-----

···

From: 7stud -- Sent: Friday, September 09, 2011 4:28 PM Newsgroups: comp.lang.ruby
To: ruby-talk ML
Subject: Re: null pointer given - hash

Angelo Farias wrote in post #1021017:

each and fetch hash doesn’t work

They work fine:

hash = {'a' => 10, 'b' => 20}

hash.each do |key, val|
  puts "#{key} = #{val}"
end

--output:--
a = 10
b = 20

puts hash.fetch('c', "sorry")

--output:--
sorry

--
Posted via http://www.ruby-forum.com/\.