#!/usr/bin/perl

#use strict;
use POSIX;
use DBI;



my $logfile = shift or die "No log-file given.";
my $stressfile = shift or die "No stress-test log-file";
my $dbfile = shift or die "No db-upload log-file";
open IN, "<$logfile";

while (<IN>) {

    
    if ( /^Name:\s*([1234][AB])_(\d*)/) {
	$type = $1;
	$number = $2;
	
    }
connect('dbi:mysql:robtestproduction:robtestdb.physi.uni-heidelberg.de:3306',
		       'robocop', 'trdrob01',
		       {'RaiseError' => 1});


$dbh->begin_work();

#if ($result eq 1){
#	$sth = $dbh->prepare("REPLACE INTO allboards(SerialNumber, BoardType, State) VALUES (?,?,?)");
#	 $sth->execute($number, "T$type","good");
#}
#else {
#        $sth = $dbh->prepare("REPLACE INTO allboards(SerialNumber, BoardType, State) VALUES (?,?,?)");
#         $sth->execute($number, "T$type","bad");
#
#}    

if ($result eq 1){
        $sth = $dbh->do("UPDATE  allboards SET State='good' WHERE SerialNumber=$number AND  BoardType='T$type'");
}
else {
        $sth = $dbh->do("UPDATE  allboards SET State='bad' WHERE SerialNumber=$number AND  BoardType='T$type'");
}



    
if ($scsnerr eq "OK"){
    $sth = $dbh->prepare("REPLACE INTO boardtests(SerialNumber, BoardType, TestDate,ScsnQuickTest, PreInChargeTest, TrapTest, PasaTest, NetwInTest,StressTest,OriReadoutTest, DBUpdate) 
			 VALUES (?,?,?,?,?,?,?,?,?,?,?)");
		 
    $sth->execute($number, $type,$date, $scsnerr, $chinjerr,$traperr,$pasaerr,$nierr, $stresserr, $orierr, $dberr);
   
}
else{
$sth = $dbh->prepare("REPLACE INTO boardtests(SerialNumber, BoardType, TestDate,ScsnQuickTest) 
			 VALUES (?,?,?,?)");
		 
    $sth->execute($number, $type,$date, $scsnerr);
   
}




$dbh->commit;



$sth->finish();
$dbh->disconnect;



	



