#!perl -w use strict; use DBI; my $drop_tables = 1; my $create_tables = 1; my $dbh=DBI->connect("dbi:SQLite2:dbname=Store.db","","", {RaiseError=> 1}) or die "$!"; if( $drop_tables == 1 ){ #NO SUPPORT for IF EXISTS $dbh->do("DROP TABLE ISP"); $dbh->do("DROP TABLE UnityPrimary"); $dbh->do("DROP TABLE UnitySecondary"); } if( $create_tables == 1){ $dbh->do("CREATE TABLE ISP(Store INTEGER,Date CHAR[1] NOT NULL )") or warn "$!"; #Define my own $dbh->do("CREATE TABLE UnityPrimary(Store INTEGER,Date CHAR[9] NOT NULL)"); $dbh->do("CREATE TABLE UnitySecondary(Store INTEGER ,Date CHAR[9] NOT NULL )"); } #open(CSV,"reboots.csv")||die"Can't open: $!\n"; while(){ chomp; my($store,$isp,$pri,$sec)=split /,/; my $sta=$dbh->prepare("INSERT INTO ISP(Store,Date) VALUES(?,?)"); my $stb=$dbh->prepare("INSERT INTO UnityPrimary(Store,Date) VALUES(?,?)"); my $stc=$dbh->prepare("INSERT INTO UnitySecondary(Store,Date) VALUES(?,?)"); $sta->execute( $store, $isp ); $stb->execute( $store, $pri ); $stc->execute( $store, $sec ); } #close CSV; my $sth=$dbh->prepare("SELECT * FROM UnityPrimary WHERE Store > 1"); $sth->execute; while(my@row=$sth->fetchrow_array){ print "@row\n"; } $dbh->disconnect; __DATA__ 1,18-Oct-04,29-Oct-04,29-Oct-04 notanInt,18-Oct-04,26-Oct-04,26-Oct-04 3,21-Oct-04,26-Oct-04,11-Aug-04 4,20-Oct-04,11-Jun-04,27-Oct-04 5,18-Oct-04,3-Sep-04,24-May-04 6,17-Oct-04,15-Oct-04,15-Oct-04