You have to create the table first. I don't think DBD::SQLite supports some syntax like LOAD DATA LOCAL INFILE 'blah.txt' INTO TABLE foo like MySQL and friends. All you need is something like (untested):
use DBI;
my $file = "C:/test.txt";
my $dbh = DBI->connect("dbi:SQLite:dbname=dbfile","","");
create the table to suit
my $sql =<<SQL;
CREATE TABLE stuff (
id INT,
field CHAR(32),
PRIMARY KEY(id) )
SQL
$dbh->do( $sql ) or die "Can't create table\n" . $DBI::errstr;
need as many ? bind values as fields
my $sth = $dbh->prepare( "INSERT INTO stuff VALUES(?,?)");
open TXT, $file or die $!;
while(<TXT>) {
chomp;
my ( $id, $field ) = split "\t"; # or whatever delim
$sth->execute( $id, $field );
}
close TXT;
$sth->finish;
$dbh->disconnect;
print "Done!\n";
|