[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Omaha.pm] Another 10 minute DB load hack



800 lines of Excel spreadsheet into a database in 15 minutes...

j


#!/usr/bin/perl

use Omni::DB;

my $dbh = Omni::DB::connect_prod;
$dbh->do("delete from user_attrib where system = 'CMS'");
my $strsql = "insert into user_attrib values (?, 'CMS', ?, ?)";
my $sth = $dbh->prepare($strsql);

while (<DATA>) {
   chomp;
   next unless (/\w/);
   tr/a-z/A-Z/;
   s/ADMINISTRATOR/ADMIN/;
   @l = split /\t/;
   $l[1] =~ s/\@.*//;
   #print "$l[1]|$l[2]|$l[0]|\n";
   $sth->execute(@l[1,2,0]);
}
$dbh->commit;
$dbh->disconnect;


__DATA__
Manager bgarlington@nospam.com      DALLBJ
User    gguyse@nospam.com   DALLBJ
User    ckreklow@nospam.com DALLBJ
...etc...