##########################################################################
#
# routine: db_otfr_stats_rp.pl
#
# Purpose: Update the pod_retr_stop_time in the otfr_request_stats
#          relation.
#
# Input:   $REQUEST  - name of OTFR request
#          $RSP_TIME - time at which response was recvd from DADS
#          ENV.ARCH_SERVER - name of DB server
#          ENV.ARCH_DB - name of database containing requests relation
#
# Output:  none
#
# Return:  number of records updated (should = 1, if successful)
#
# Calls:   PrintMsg
#
# modification history:
#
#   date    opr     who     reason
# -------- -----  --------  --------------------------------------
# 09/03/00 43165  MSwam     first version
# 04/04/03 43915  WMiller   DADS 10.0 support
# 03/25/10 64274  MSwam     Replace ST_DBlib with DBI
# 06/30/10 64432  MSwam     Use single quotes for SQLServer
# 
#########################################################################
sub DB_otfr_stats_rp{
    my ($ROOTNAME, $REQUEST, $RSP_TIME) = @_;        # ARGUMENTS from @_
    my ($db, $query, $count);  # LOCAL VARS

    require 'do_dbi_pkg.pl';

    $server = $ENV{"ARCH_SERVER"};
    $database = lc($ENV{"ARCH_DB"});
    my $db = STScI::DBI->connect( "dbi:Sybase:server=$server");
    if (!defined($db)) {
        PrintMsg("E","Cannot connect to server: $DBI::errstr");
        return;
    }
    DoDBI($db,"use $database"); # open database

    $query = <<"EOQ";
UPDATE otfr_request_stats
SET ors_pod_retr_stop_time = '$RSP_TIME'
WHERE ors_otfr_request_id = '$REQUEST'
AND ors_data_set_name = '$ROOTNAME'
EOQ

    $count = DoDBI($db, $query);
    if ($count == 1) {
        PrintMsg("I", "updated $count record in otfr_request_stats");
    }
    else {
        PrintMsg("E", "Update FAILED for otfr_request_stats: $REQUEST\n");
    }
    DoDBIclose($db);
}
1;
