#!/usr/bin/perl

use DBI;

my $dsn = 'DBI:mysql:<dbname>:<dbhost>';
my $db_user_name = '<dbusername>';
my $db_password = '<dbpassword>';
my ($id, $password);
my $dbh = DBI->connect($dsn, $db_user_name, $db_password);

 my $sth = $dbh->prepare(qq{
             select max(queueid) from queue_actions where nodename = '<asthost>' });
 $sth->execute();

 ($maxid) = $sth->fetchrow_array();
 $sth->finish();

 open (QLOGF, "<$ARGV[0]");

 while ($qlogstr = <QLOGF>) {

        chop($qlogstr);
        @bdownstr = split(/\|/, $qlogstr, 7);
        if ($bdownstr[0] > $maxid) {

	if ($bdownstr[4] eq "ABANDON") {
		($pos, $holdtime) = split(/\|/, $bdownstr[6]);
		$bdownstr[6] = $holdtime;
	}

        $sqlstr = qq|insert into queue_actions (queueid, uniqueid, queuename, agentname, action, alt1
, alt2, userfield, calltype, nodename) values ($bdownstr[0], '$bdownstr[1]', '$bdownstr[2]', '$bdownstr[3]', '$bdownstr[4]', '$bdownstr[5]', '$bdownstr[6]', '', null, '<asthost>')|;

        $dbh->do($sqlstr);
        }

 }

 close (QLOGF);
$dbh->disconnect();


