Jason Hsu, Android developer wrote in post #1103930:
p.queryUserTable {|row| printf("%d %s\n", row['id'], row['name'])}
This line has done exactly what you're asking. The "row" is a hash
variable that contains the data from the database. If you want to put
that data a variable of your own the just define a variable and put the
data in it:
# Add the name from each row in an array
my_arrary = []
p.queryUserTable do |row|
my_array << row['name']
end
puts my_array
In fact if you look at this line:
@conn.exec( "SELECT * FROM users" ) do |result|
All the data from the table is already given to you inside the "result"
hash, which is just a variable containing the data you selected from the
database. There's really no need to make yet another variable to put the
data into. Just use the one the PostgreSQL connection gives you back.
--
Posted via
http://www.ruby-forum.com/.