EvanK has asked for the wisdom of the Perl Monks concerning the following question:
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:
However, any INSERT statements I try to execute from the same script, on the same db handle, simply fail.# "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"; }
This gives me the following erorr:# 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; }
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.INSERT failed: near ")": syntax error(1) at dbdimp.c line 271
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: DBD::SQLite will connect and CREATE, but not INSERT...sort of
by bart (Canon) on Apr 23, 2007 at 22:42 UTC | |
|
Re: DBD::SQLite will connect and CREATE, but not INSERT...sort of
by Fletch (Bishop) on Apr 23, 2007 at 20:15 UTC | |
by EvanK (Chaplain) on Apr 23, 2007 at 21:14 UTC | |
by wjw (Priest) on Apr 24, 2007 at 03:18 UTC | |
|
Re: DBD::SQLite will connect and CREATE, but not INSERT...sort of
by dragonchild (Archbishop) on Apr 23, 2007 at 20:11 UTC |