I don't know why I can't insert for the type field.
Maybe if you print $sql before executing it, you see what's wrong. I did:
"cash" isn't quoted, so the SQL engine thinks it's a column or variable name. The solution to your problem is to either use quotes in the format string (bad), or to use placeholders (good). Placeholders were designed for this problem. Placeholders work much like sprintf, so understanding how they work shouldn't be a problem for you. Still, it's a good idea to read in DBI's documentation what they have to say about it.INSERT INTO sales VALUES(10112, 6768, cash, 1020, 780, 1)
In this example I will use DBIx::Simple, because typing (??) is much easier than typing (?, ?, ?, ?, ?, ?) and I am lazy.
#!/usr/bin/perl -w use strict; use DBIx::Simple; my $db = DBIx::Simple->new('dbi:SQLite:mydb.txt', '', '', { RaiseError + => 1 }); eval { $db->query( 'CREATE TABLE sales (customer, vendor, type, product, app, res +ult)' ); }; while (<DATA>) { $db->query('INSERT INTO sales VALUES (??)', split); } __DATA__ ...
RaiseError lets the program die on errors. This saves a lot of "or die" typing. The eval is there to allow the CREATE TABLE statement to fail. (It'll fail if the table already exists.)
hth
Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }
In reply to Re: Can't insert into for one column
by Juerd
in thread Can't insert into for one column
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |