Phillip Gawlowski
3/26/2007 1:53:00 PM
Paul Willis wrote:
> Hi
>
> I am playing with Ruby/MySQL, I have everything installed ok. I can
> INSERT into my database but I am having trouble with SELECT.
>
> I want to see if the text in the field 'title' has been used before and
> if it has return the id of that row. If I run...
>
> require "mysql"
> my = Mysql::new("hostname", "username", "password", "db")
> hasid = my.query("SELECT id FROM table WHERE title = 'Here is a title'")
> puts hasid
>
> I get a result like...
>
> #<Mysql::Result:0x55c74c>
>
> I am expecting just the number in the id field. Any ideas?
hasid.each do |row|
puts row
end
Keep in mind, that Ruby/MySQL doesn't "rewind" after using an iterator.
I've circumvented that by doing the following:
array = Array.new
hasid.each do |row|
array.push(row)
end
I haven't tested the code, but it mirrors the code I use, sans
implementation details special to my program.
--
Phillip "CynicalRyan" Gawlowski
Rule of Open-Source Programming #9:
Give me refactoring or give me death!