From: Panagiotis Atmatzidis Date: 2012-12-14T03:19:26+09:00 Subject: Re: Database query Hello, On 13 Δεκ 2012, at 17:56 , cristian cristian wrote: > Thank you for the help! > Panagiotis I will look into datamapper but now Im stuck with this > problem... :) Datamapper will help you solve this problem (and other syntax problems) as it uses hashes widely and it's syntax is much more 'rubyish'. However, the code 7stud guru posted is working perfectly. Take a look here --------------------------------------------------------------------------------------------------------------- ➜ archive git:(master) ✗ sqlite3 hellenic_words.db SQLite version 3.7.14.1 2012-10-04 19:37:12 Enter ".help" for instructions Enter SQL statements terminated with a ";" sqlite> .tables hellenic_words_databases sqlite> select * from hellenic_words_databases; 1|καλημέρα|feea7f066965d3a9f1f19e67a4fcc5d81f313210|2012-12-11T15:27:27+01:00|||||| 2|αλήθεια|8f01e8dbc7dc7c64ae80daa6558dcad679f48e3d|2012-12-11T15:27:27+01:00|||||| 3|αγάπη|187adbb275e4e1df0caf32087f0dc0957fc1474b|2012-12-11T15:27:27+01:00|||||| 4|Ελλάδα|d2e38adc17e42d109fdb946f564e70aa84f994d7|2012-12-11T15:27:27+01:00|||||| 5|στροφή|0c3dbbf9303a42c0b678db7d59ff1c5aa53b8a12|2012-12-11T15:27:27+01:00|||||| 6|αναποδιά|e22383f69bf6a033009057739a52bc16f87d4f2d|2012-12-11T15:27:27+01:00|||||| 7|τιμόνι|b79aafd3f543ebefba9430d8e0d0033ed5072a89|2012-12-11T15:27:27+01:00|||||| 8|αδελφή|24897aaa317b0dec6bb01d3abcbf17048cb8b6e3|2012-12-11T15:27:27+01:00|||||| 9|ποταμός|95ae1fed2b86c551911e78f107f38b777c777d9a|2012-12-11T15:27:27+01:00|||||| 10|κανάτα|cf951867e94cf8474e5ccd700966b2c603d9ebf4|2012-12-11T15:27:27+01:00|||||| 11|φασολάδα|e5ea942c97d8c0f2c9a37cd0f1a271beeedb5a98|2012-12-11T15:27:27+01:00|||||| 12|παιχνίδι|d752a274657538e752e6eeedbd34a1359ac11d8d|2012-12-11T15:27:27+01:00|||||| 13|παπούτσι|2eaea11ab23d6ac0a7497f978887f4f6330c1fce|2012-12-11T15:27:27+01:00|||||| 14|παντόφλα|e68e9ad399ddce4572fd7a7ed33962dda842b231|2012-12-11T15:27:27+01:00|||||| 15|κομοδίνο|dafd4a50b1ff983cd1cfff7160320c64af3ee7fe|2012-12-11T15:27:27+01:00|||||| 16|δίσκος|5a3a80cc90756999bab5b81775311be2e096e873|2012-12-11T15:27:27+01:00|||||| 17|κουτί|ff7f9d9b16a51770a31863f9296cb903af97d0e9|2012-12-11T15:27:27+01:00|||||| sqlite> .quit ➜ archive git:(master) ✗ ruby sample.rb word => καλημέρα sha1 => feea7f066965d3a9f1f19e67a4fcc5d81f313210 0 => καλημέρα 1 => feea7f066965d3a9f1f19e67a4fcc5d81f313210 ******************** word => αλήθεια sha1 => 8f01e8dbc7dc7c64ae80daa6558dcad679f48e3d 0 => αλήθεια 1 => 8f01e8dbc7dc7c64ae80daa6558dcad679f48e3d ******************** word => αγάπη sha1 => 187adbb275e4e1df0caf32087f0dc0957fc1474b 0 => αγάπη 1 => 187adbb275e4e1df0caf32087f0dc0957fc1474b ******************** [...] ➜ archive git:(master) ✗ cat sample.rb #!/usr/bin/env ruby # encoding: UTF-8 require 'sqlite3' db = SQLite3::Database.open('hellenic_words.db') db.results_as_hash = true result_set = db.execute( "SELECT word,sha1 FROM hellenic_words_databases" ) result_set.each do |row| row.each { |key, value| puts "#{key} => #{value}" } puts '*' * 20 end --------------------------------------------------------------------------------------------------------------- So you're obviously doing something wrong :-) > This always puts 'Nothing' even though I know I have a Key==7 in the > table. I miss something... Any suggestions? > > result_set = db.execute( "SELECT Key,Url FROM Sites" ) > > result_set.each do |row| > row.each do |key, value| > if key=='7' > puts "#{key} => #{value}" > else > puts "Nothing" > end > puts '*' * 20 > end > end > > > Br > cristian > > -- > Posted via http://www.ruby-forum.com/. > Have a nice day! Panagiotis (atmosx) Atmatzidis email: atma@convalesco.org URL: http://www.convalesco.org GnuPG ID: 0xE736C6A0 gpg --keyserver x-hkp://pgp.mit.edu --recv-keys 0xE736C6A0 -- The wise man said: "Never argue with an idiot. They bring you down to their level and beat you with experience."