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);
In reply to Query Formatting by ShayShay
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |