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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |