#!/usr/bin/env perl 
#----------------------------------------------------------------------------
#
# Name: otfr_stats_e.pl
#
# This perl script fills part of a database record in the "otfr_request_stats"
# relation using information gleaned from an OTFC request file.
# This script performs an update of the "trouble_flag" field, setting it to T.
#
# Usage:
#	% otfr_stats_e.pl otfcid
#
#	Note that the following environment variables (logicals) are required:
#       ARCH_SERVER and ARCH_DB
#
# History:
# Date     OPR      Who         Reason
# -------- -------- ----------  ---------------------------------------------
# 12/21/00 43165    MSwam       first version
# 04/04/03 43915    WMiller     DADS 10.0 support
# 03/25/10 64274    MSwam       Replace ST_DBlib with DBI
#
#----------------------------------------------------------------------------
#
# adjust the Perl include dir using PATH
$PATH=      $ENV{"PATH"};
@parts = split /:/, $PATH;
while (defined($val = pop(@parts))) {
    if (substr($val,0,1) eq "/") { unshift(@INC, $val)}
}

# get the external variables
$ARCH_SERVER=      $ENV{"ARCH_SERVER"};
$ARCH_DB=      lc($ENV{"ARCH_DB"});

$usage = "USAGE: otfr_stats_e.pl otfcid rootname";

require 'printmsg.pl';	# PrintMsg routine
require 'do_dbi_pkg.pl';	# RunSql routine

# begin

    #
    # verify arguments are present
    #
    if ($#ARGV != 1) {  
        die "$usage\n";
    }
    $otfc_id    = $ARGV[0];
    $rootname   = uc($ARGV[1]);

    #
    # initialize database
    PrintMsg ("I","--- start --- update trouble_flag in otfr_request_stats ----------");
	 
    $my $EXIT_FAILURE = 1;
    $db = DoDBIopen( $ARCH_SERVER, $ARCH_DB, $EXIT_FAILURE);

    $query = <<"EOQ";
UPDATE otfr_request_stats
SET    ors_trouble_flag = 'T'                             
WHERE  ors_otfr_request_id = \'$otfc_id\'
AND    ors_data_set_name   = \'$rootname\'
EOQ

    $count = DoDBI( $db, $query );
    if ($count == 1) {
        PrintMsg("I","Updated 1 record in otfr_request_stats\n");
    }
    else {
        PrintMsg("E","Updated $count records in otfr_request_stats\n");
    }

#---------------------------------------------------------------------
# end of all queries
#---------------------------------------------------------------------
    DoDBIclose($db);
    PrintMsg ("I","---  end  --- update trouble_flag in otfr_stats ----------");
    exit( 0);  # EXIT_SUCCESS

