#! /usr/bin/perl


use DBI;
sub Init()
{ 
    $PREPARE_FAILED=8;
    $EXECUTION_FAILED=9;
    $SUCCESS = 0;
    $dbh = DBI->connect("DBI:Pg:dbname=manager","postgres","DB200\@midWill")
	or die "Couldn't connect to database: " . DBI->errstr;
    return $SUCCESS;
}

sub LoadTableDetails
{
    if(ExecuteQry("db","tbl" ,"select recordid,agentid,additionalattributes from activealarms order by agentid;") == $SUCCESS)
    {
	while ( @row = $sth->fetchrow_array ) 
	{
	    printf "@row\n";
	}
    }
    else
    {
	printf("error loading agentdetails");
    }
}

sub ExecuteQry
{
    $STATUS = $SUCCESS; 
    
    $sth = $dbh->prepare("$_[2]")
	or $STATUS = $PREPARE_FAILED;
    
    if ($STATUS == $PREPARE_FAILED)
    {
    	return $STATUS;
    }
    
    $sth->execute
    	or $STATUS = $EXECUTION_FAILED;
    
    if ($STATUS == $EXECUTION_FAILED)
    {
    	return $STATUS;
    }
    return $SUCCESS;
}

Init();
LoadTableDetails();

