title: How do I deal with the results of a sqlite query in ruby?
body: <p>I have a simple task before me, query a database for the existence of a certain row via ruby's sqlite3 library. Below find my attempt. </p>
  
  <p>There has got to be a better (less verbose) way than below. What is it? Is there something about Ruby's "Enumerable" class that I should be looking at? How do I determine the data type of sql results in general?</p>
  
  <pre><code>#!/usr/bin/env ruby
  
  require 'sqlite3'
  
  db = SQLite3::Database.open "example.db"
  
  db.execute "create table if not exists example (id INTEGER PRIMARY KEY, words TEXT, whence DATETIME, number INT)"
  
  words = "words"        
  
  begin 
     insert = db.prepare "insert into example (words,whence,number) values (?,?,?)"
     insert.bind_param 1, words
     insert.bind_param 2, Time.now.to_s
     insert.bind_param 3, 42
     insert.execute
  rescue SQLite3::Exception =&gt; e 
     puts "Problem with insert"
     puts e
  end    
  
  begin
      query = db.prepare "select count(*) as count from example where words = ?"
      query.bind_param 1, words
      rs = query.execute
  
      #puts rs.first
      res = rs.first.to_a
  
      puts res
      #if (rs.first.to_s.to_i &gt; 0)
      if (res.first.to_i &gt; 0)
          puts "rs.first greater than 0"
      else 
          puts "it won't get here."
      end 
  
      #if (rs.first == nil 
      #    puts "result is nil"
      #else 
      #    puts "result is NOT nil"
      #end
  
  rescue SQLite3::Exception =&gt; e
      puts "Problem with query"
      puts e
  end
  </code></pre>