Y
Yuriy Skobov
Hi,
I'm just learning Ruby with SQLite3 and I ran into this problem with the
tutorial. After creating a database using this:
$db = SQLite3:atabase.new("dbfile")
$db.results_as_hash = true
def create_table
puts "Creating people table"
$db.execute %q{
CREATE TABLE people (
id integer primary key,
name varchar(50),
job varchar(50),
gender varchar(6),
age integer)
}
end
I use the following to insert a new row into the database:
$db.execute("INSERT INTO people ( name, job, gender, age ) VALUES ( ?,
?, ?, ? )", name, job, gender, age)
However, the first value (name, in this case) gets ignored and is still
assigned NIL when this is done. I've tried hardcoding the first value
using \"Some Name\", but then the second seems to have the same problem
instead, so I'm pretty sure it's something with the placeholders.
Any idea what this might be? I thought I might be typing something
wrong, but after downloading and running the supplied source code
(attached), I got the same problem.
Attachments:
http://www.ruby-forum.com/attachment/4816/listing20.rb
I'm just learning Ruby with SQLite3 and I ran into this problem with the
tutorial. After creating a database using this:
$db = SQLite3:atabase.new("dbfile")
$db.results_as_hash = true
def create_table
puts "Creating people table"
$db.execute %q{
CREATE TABLE people (
id integer primary key,
name varchar(50),
job varchar(50),
gender varchar(6),
age integer)
}
end
I use the following to insert a new row into the database:
$db.execute("INSERT INTO people ( name, job, gender, age ) VALUES ( ?,
?, ?, ? )", name, job, gender, age)
However, the first value (name, in this case) gets ignored and is still
assigned NIL when this is done. I've tried hardcoding the first value
using \"Some Name\", but then the second seems to have the same problem
instead, so I'm pretty sure it's something with the placeholders.
Any idea what this might be? I thought I might be typing something
wrong, but after downloading and running the supplied source code
(attached), I got the same problem.
Attachments:
http://www.ruby-forum.com/attachment/4816/listing20.rb