I'm having a bit of a problem with a project that I'm hoping you all can help me out with. I've looked over some of the documentation and done google searches, but I still can't get it to work.

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.