zentara has asked for the wisdom of the Perl Monks concerning the following question:
And my select statement:sqlite> .schema CREATE TABLE info ( key, name, location, pic, thumbnail, color, comment, Personal, Test_Scores, Background, Classes, Sports, Problems, Awards, Other ); sqlite>
It's just what I want.sqlite> select * from info where key = 'ScottyZ'; ScottyZ|ScottyZ||pics/ScottyZ.jpg|thumbs/ScottyZ.jpg|lightsteelblue|ni +ce|||||||| sqlite>
Now if I do the same thing from Perl, I get a error.
I get the error:my $cmd = "select * from info where key = $key_sel"; $sth = $dbh->prepare($cmd); $sth->execute; my @row; while (@row = $sth->fetchrow_array() ){ print "@row\n"; my $key = $row[0]; }
now the only clue I have, is that I must put single quotes around 'ScottyZ', when I run the sqlite c program; and if I omit the single quotes, the c version of sqlite throws the same error as the Perl script.DBD::SQLite::st execute failed: no such column: ScottyZ at ./ztkdb1d l +ine 395. Tk::Error: dbih_setup_fbav: invalid number of fields: 0, NUM_OF_FIELDS + attribute probably not set right at ./ztkdb1d line 398. main::browseThis at ./ztkdb1d line 398
I've tried all sorts of different syntax in $cmd, trying to isolate $key_sel, but to no avail. I've changed = to == and eq , so that isn't the glitch.
I do get my script working with the following hack:
So what am I doing wrong in Perl, should I not use $sth?print "$key_sel\n"; my $cmd = "select * from info"; $sth = $dbh->prepare($cmd); $sth->execute; my @row; while (@row = $sth->fetchrow_array() ){ next unless $row[0] eq $key_sel; print "@row\n"; my $key = $row[0]; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: DBD::SQLite select syntax problem
by gmax (Abbot) on Feb 12, 2004 at 23:31 UTC | |
Re: DBD::SQLite select syntax problem
by zentara (Cardinal) on Feb 12, 2004 at 23:55 UTC |