File: [local] / wpscripts / zstatus / zstatus.pl (download)
Revision 1.2, Wed Jul 20 07:42:05 2011 UTC (12 years, 9 months ago) by yason
Branch: MAIN
Changes since 1.1: +11 -13 lines
new sql credentials. we need only tiff and proba status
|
#!/usr/bin/perl
# $Id: zstatus.pl,v 1.2 2011/07/20 07:42:05 yason Exp $
use DBI;
my $DB_SERVER = "pdc"; # from /usr/local/etc/freetds.conf
my $DB_USER = "sa";
my $DB_PASS = "aekghbynflvby";
my $dsn = "DBI:Sybase:server=$DB_SERVER";
my $dbh;
my $sth;
my $numcard;
my $type;
my $value;
my @status;
if(scalar(@ARGV) != 3 || $ARGV[1] ne "tiff" && $ARGV[1] ne "proba")
{
print "Usage:\n";
print "zstatus <NumCard> <tiff|proba> <value>\n";
exit(-1);
}
$numcard = shift;
$type = shift;
$value = shift;
if($value != 0 && $value != 1)
{
print "Status value out of range: valid values are 0 or 1\n";
exit(-1);
}
$dbh = DBI->connect($dsn, $DB_USER, $DB_PASS) or die("Can not connect to database!");
$dbh->do("use full_print");
$sth = $dbh->prepare("SELECT ID,status from upload_files WHERE numcard=$numcard AND type_file=0") if($type eq "tiff");
$sth = $dbh->prepare("SELECT ID,status from upload_files WHERE numcard=$numcard AND type_file=1") if($type eq "proba");
$sth->execute( );
@status = ($sth->fetchrow_array( ));
if(!$status[0])
{
print "$type with NumCard=$numcard not found in the database!\n";
exit(-1);
}
$sth = $dbh->prepare("UPDATE upload_files SET status=$value WHERE numcard=$numcard AND type_file=0") if($type eq "tiff");
$sth = $dbh->prepare("UPDATE upload_files SET status=$value WHERE numcard=$numcard AND type_file=1") if($type eq "proba");
$sth->execute( ) or die("Can not execute SQL");
print "status changed from $status[1] " . ($status[1] == 0 ? "(NOT SENT)" : "(SENT)") . " to $value " . ($value == 1 ? "(SENT)" : "(NOT SENT)") . "\n";