I would like to know how to insert faster using
SQLite.

use strict;
use dbi;
use Date::Manip;
use Diagnostics;

#Connect to the database
my $dbh = DBI->connect("dbi:SQLite:data.dbl")
  || die "Cannot connect: $DBI::errstr";

#MSSQL Server
my $kewilldb = 'LV_KWARCHIVE';

my $dbh_kewill = DBI->connect( "dbi:ODBC:$kewilldb",
'kewill', 'kewill' )
  || die "Cannot connect to Kewill: $DBI::errstr";

$dbh->do("DROP TABLE zipcode5");
$dbh->do("CREATE TABLE zipcode5 ( destzip, count )");
my $sth_insertzipdata = $dbh->prepare("insert into
zipcode5 values(?,?)")
  || die "Cannot prepare insert into zipcode5\n";

&getKewillData;

$dbh->disconnect;
$dbh_kewill->disconnect;

sub getKewillData {
    my $tempdate  = &DateCalc( "today", "-15days " );
    my $tempdate1 = &DateCalc( "today", "-45days " ); 
# get time of 45 days ago

    my $todate   = &UnixDate( $tempdate1, "%Y-%m-%d
00:00:00" );
    my $fromdate = &UnixDate( $tempdate,  "%Y-%m-%d
23:59:00" );
    print "tempdate $tempdate tempdate1 $tempdate1
$todate $fromdate   ", "\n";

    my $sth_kewill = $dbh_kewill->prepare(
        "select destzip,count(*) from shipments
                                        where datecreated > ?
                                        and datecreated < ?
                                        and CarrierCode = 'USP'
                                        group by Destzip"
      )
      or die "Cannot Prepare Kewill Zip Code:
$DBI::errstr";

    $sth_kewill->execute( $todate, $fromdate )
      or die "Cannot execute kewill query\n";

    my $ary_ref = $sth_kewill->fetchall_arrayref;

    foreach (@$ary_ref) {
        print "$_->[0], $_->[1]\n";

        $sth_insertzipdata->execute($_->[0],$_->[1]);

    }

}



=====
Joseph Lamb


                
_______________________________
Do you Yahoo!?
Declare Yourself - Register online to vote today!
http://vote.yahoo.com

Reply via email to