Dear monks While discovering prepared statements with perl/dbi and sqlite I'like to optimize a piece of code I wrote as it is so slow...

The code below takes ages to insert some 6000 lines from a text file.

What could I easily improve?

Some guidance largely accepted as I'm not fully familiar with prepared statements yet.

Thanks for your guidance.

SebRoux

use DBI; my $dbfile = 'database.db'; # your database file my $dbh = DBI->connect( # connect to your database, create if "dbi:SQLite:dbname=$dbfile", # DSN: dbi, driver, database file "", # no user "", # no password { RaiseError => 1 }, # complain if something goes wrong ) or die "Cannot connect $DBI::errstr"; $dbh->do("DROP TABLE IF EXISTS log"); $dbh->do( "CREATE TABLE log ('date','time','server','application','database','us +er','msglevel','msgcode','msgcat','description')" ); #Parsing log $temp = "C:\\eclipse\\workspace\\Rightlog\\test.txt"; open( LOGFILE, "$temp" ) or die print "Error: could not open $temp\n"; $sth = $dbh->prepare("INSERT INTO log VALUES (?,?,?,?,?,?,?,?,?,?)"); while (<LOGFILE>) { chomp; my ( $date, $time, $server, $application, $database, $user, $msglevel, $msgcode, $msgcat, $description ) = split /\|/; $sth->execute( $date, $time, $server, $application, $database, $user, $msglevel, $msgcode, $msgcat, $description ); } close(LOGFILE); $dbh->commit; $dbh->disconnect();

In reply to Optimize sqlite prepared statement by sroux

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.