DISCLAIMER: in the interests of full disclosure, I am currently coding and testing on a Mac OS X 10.4.9 system (due to variables beyond my control).

I'm writing a small web app that is initially given a csv file (specifically a csv export from an excel file), and I want to convert it to a sqlite database using DBD::SQLite, but I'm running into a strange issue. I can create the connection (and the actual database file) without incident, and can even issue a table CREATE statement without a problem:

# "connect" to sqlite database file, creating it if it doesnt exist my $dbh = DBI->connect("dbi:SQLite:dbname=testing.sqlite","",""); # build/execute a CREATE statement from array of column names with all + rows as type 'TEXT' my $sql = sprintf 'CREATE TABLE rowdata ( %s )', join(' TEXT, ', @head +ers, ' TEXT'); $status = $dbh->do($sql); # return error status if CREATE resulted in error if (!defined $status) { die "CREATE failed"; }
However, any INSERT statements I try to execute from the same script, on the same db handle, simply fail.
# build/execute an INSERT statement from array of field values # note: all of these values are already DBI quoted my $sql = sprintf 'INSERT INTO rowdata VALUES( %s )', join(',', @row); $status = $dbh->do($sql); # return error status if INSERT resulted in error if (!defined $status) { die "INSERT failed: ", $dbh->errstr; }
This gives me the following erorr:
INSERT failed: near ")": syntax error(1) at dbdimp.c line 271
At first, I assumed it was a permission issue of some kind, but it actually creates the database file (permissions of which are 755), and succeeds with the CREATE statement which also modifies the file. Additionally, I printed the built queries directly to the screen, then input them one at a time via an interactive debugger session, and this worked without any problems.

I'm thoroughly puzzled, could anyone know what's causing this?

__________
Systems development is like banging your head against a wall...
It's usually very painful, but if you're persistent, you'll get through it.


In reply to DBD::SQLite will connect and CREATE, but not INSERT...sort of by EvanK

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.