sroux has asked for the wisdom of the Perl Monks concerning the following question:

Dear monks, The mid experienced perl user I'm, is getting interested in sqlite. I installed DBD-SQLite and Perl DBI and be interested in bulk loading a table or importing a file into a table... Which would be the steps I have to follow as there's no bulk insert function/method available... Any help/link of interest are higly welcomed. SebRoux

Replies are listed 'Best First'.
Re: Perl + sqlite + bulk insert
by salva (Canon) on Jun 03, 2008 at 22:26 UTC
    You can dump the data to a temporary file, and them call the sqlite utility with a driver script that imports the temporary data file using an .import directive.
    open my $temp, '>', $temp_filename or die ...; for (@data) { print $temp join('|', ...), "\n"; } open my $driver, '>', 'import.sql'; print $driver ".import $temp_filename\n"; ... system sqlite3 => -init => 'import.sql', $dbfile => '.quit';
Re: Perl + sqlite + bulk insert
by kyle (Abbot) on Jun 03, 2008 at 20:15 UTC

    From a little Googling around, I found two options.

    • Use COPY to bring in your data from a prepared file.
    • Use a prepared INSERT statement between BEGIN and END.