SQLite placeholder problem

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::Database.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
 
W

Waldemar Dick

Hi,

Am 23.06.2010 08:29, schrieb Yuriy Skobov:
[...]
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

The attached version works fine on my machine:
Windows XP with:
- sqlite3 3.6.10
- gem sqlite3-ruby-1.2.5
- ruby 1.9.1p376 (2009-12-07 revision 26041) [i386-cygwin]

Waldemar
 
Y

Yuriy Skobov

I thought it might have been a Windows vs. Cygwin issue, so I went back
to Cygwin on this one. Had a lot of not_fun because there was
interference with the Windows installation of Ruby. However, once I got
Cygwin back on track (after uninstalling Windows installation of Ruby),
I saw the same problem.
I'm using:
Windows 7 64-bit
sqlite3-ruby (1.3.0)
ruby 1.8.7 (2008-08-11 patchlevel 72) [i386-cygwin]

Should I try to match your version and see if that works?
 
Y

Yuriy Skobov

Waldemar said:
Windows XP with:
- sqlite3 3.6.10
- gem sqlite3-ruby-1.2.5
- ruby 1.9.1p376 (2009-12-07 revision 26041) [i386-cygwin]

Found it. It was the gem sqlite3-ruby-1.3.0 that was causing this.
With version 1.2.5, it works like it's supposed to.
 
F

fistfvck

hi.

see blow.
sqlite3-ruby-1.3.0/lib/sqlite3/database.rb:119
warn(<<-eowarn) if $VERBOSE
#{caller[0]} is calling SQLite3::Database#execute with nil or
multiple bind params
without using an array. Please switch to passing bind parameters as an a=
rray.
eowarn

so, change like this:
listing20.rb:33
$db.execute("INSERT INTO people (name, job, gender, age) VALUES (?,
?, ?, ?)", [name, job, gender, age])

listing20.rb:40
person =3D $db.execute("SELECT * FROM people WHERE name =3D ? OR id =3D
?", [id, id.to_i]).first

Regards
2010/6/24 Yuriy Skobov said:
Waldemar said:
Windows XP with:
- sqlite3 3.6.10
- gem sqlite3-ruby-1.2.5
- ruby 1.9.1p376 (2009-12-07 revision 26041) [i386-cygwin]

Found it. =A0It was the gem sqlite3-ruby-1.3.0 that was causing this.
With version 1.2.5, it works like it's supposed to.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,817
Latest member
DicWeils

Latest Threads

Top