From: cristian cristian Date: 2012-12-13T05:48:13+09:00 Subject: Database query Hi all! Im trying to learn ruby :) and I have a problem when changing a hash to a db table. I made a hash with a key and value like this: url = { "1" => "www.url1.com" "2" => "www.url2.com" .... } Then I used it like this: url.each do |number,url| if number == "1" .... else .... end Now, I made a table in SQLite3 with four columns: Key - integer Category - Numeric Description - Text Url - Text This is my little script and it works: require 'sqlite3' db = SQLite3::Database.new "test.db" db.results_as_hash = true db.execute( "SELECT Key,Url FROM Sites" ) do |site| puts "-> Site #%d %s" % [ site['Key'], site['Url'] ] end Now my problem is that I dont know how to use this instead of my hash. I thought that I could do something like this: store_as_hash = db.execute( "SELECT Key,Url FROM Sites" ) and then just use this like I did with the hash above but it doesnt work: store_as_hash.each do |number,url| if number == "1" .... else .... end I dont know if I can explain my problem in a better way....hopefully you understand..How can I use the result from the query? Br cristian -- Posted via http://www.ruby-forum.com/.