ShayShay has asked for the wisdom of the Perl Monks concerning the following question:
I'm using SQLite to try to insert a row into a table. I've got variables $gi, $orgName, and $nc that I want to use in my insert statement. I've tried several various ways of writing the statement, including using ? as values and undef afterwards, as well as playing with the " marks. Nothing seems to work.
I'm getting the error:
DBD::SQLite::db prepare failed: near "NC": syntax error(1) at dbdimp.c line 271 at C:\Perl\bin\getAllFiles.pl line 31, <FILE> line 3328.
Can't call method "execute" on an undefined value at C:\Perl\bin\getAllFiles.pl line 40, <FILE> line 3328.
Here's a condensed version of the code from "getAllFiles.pl":
use Cwd; use Net::FTP; use DBI; use strict; sub dbConnect{ my ($database, $username, $password, $hostname) = @_; my $db = DBI->connect("DBI:SQLite:$database:$hostname", $username, + $password) || die "Cannot connect to host database.".$DBI::errstr; return $db; } sub dbDisconnect{ my ($db) = @_; $db->disconnect; } sub dbQuery{ my ($query) = @_; print $query; my($database) = "myDB"; my($username) = "username"; my($password) = "password"; my($hostname) = "myHost.com"; my $db = dbConnect($database, $username, $password, $hostname); $query = $db->prepare($query); #LINE 31 $query->execute; #LINE 40 $query->finish; dbDisconnect($db); } my $gi = "11111111"; my $orgName = "some bacteria"; my $nc = "NC_000000"; my $query = "INSERT INTO ORGANISM (ORG_NAME, GI, NC) VALUES ('$gi', '$ +orgName', '$nc')"; dbQuery($query);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Query Formatting
by ikegami (Patriarch) on Dec 05, 2007 at 22:48 UTC | |
|
Re: Query Formatting
by eserte (Deacon) on Dec 05, 2007 at 22:40 UTC | |
by ShayShay (Acolyte) on Dec 05, 2007 at 22:45 UTC | |
|
Re: Query Formatting
by KurtSchwind (Chaplain) on Dec 05, 2007 at 22:55 UTC | |
by ikegami (Patriarch) on Dec 05, 2007 at 22:56 UTC | |
|
Re: Query Formatting
by tcf03 (Deacon) on Dec 06, 2007 at 10:01 UTC | |
by tcf03 (Deacon) on Dec 06, 2007 at 10:17 UTC |