mardi 1 mars 2016

How can I select a value from a database using Ruby and SQLite3?

I am having trouble returning a single value from a database using SQLite3 and Ruby.

A bit of context: I have a table of people and I would like to be able to query the database and get back the first name of someone in that table. I am using Rubymine with the SQLite3 gem.

When I run this code:

name = @db.execute <<-SQL
    SELECT firstname FROM tbl_people WHERE email_address = '#{email_address}';
  SQL
  puts name

I get the following ouput:

{"firstname"=>"james", 0=>"james"}

When really the output I am expecting is:

james

If anyone can even point me in the right direction here it would be very much appreciated.

Cheers, James

Aucun commentaire:

Enregistrer un commentaire