#!/usr/bin/perl -w # create a SQLite test database use strict; use DBI; my $db = shift || 'test'; my $dbh = DBI->connect("dbi:SQLite:$db", "","", {RaiseError => 1, PrintError=>0}) or die "can't connect\n"; my $max_fields = 20; my $field_size = 9; my $max_records = 100_000; my $max_commit = 5_000; my $text = 'abcdefghi'; my $inserted = 0; my $create_query = "create table testdbi ( " . (join ",", map {"id$_ char($field_size) not null"} (1..$max_fields)) . ", primary key (id1))"; # Drops existing table, ignoring errors. # Sort of "DROP TABLE IF EXISTS" in MySQL eval { $dbh->do(qq{drop table testdbi}) }; $dbh->do($create_query); $dbh->do('begin'); my $sth = $dbh->prepare(qq{INSERT INTO testdbi VALUES (} . (join ",", map {'?'} (1..$max_fields)) .")" ); for (1..$max_records) { $inserted += $sth->execute( map {$text++} (1..$max_fields) ); if (($inserted % $max_commit) == 0) { $dbh->do('commit'); print "$inserted\n"; $dbh->do('begin'); } } $dbh->do('commit'); print "inserted $inserted records\n"; $dbh->disconnect;