##########################################################################
#
# routine: db_otfr_stats_rq.pl
#
# Purpose: Update the pod_retr_start_time in the otfr_request_stats
#          relation.
#
# Input:   $REQUEST  - name of OTFR request
#          $REQ_TIME - time at which request was submitted to 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_rq{
    my ($ROOTNAME, $REQUEST, $REQ_TIME) = @_;     # ARGUMENTS from @_
    my ($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

    PrintMsg("I","request=$REQUEST, req_time=$REQ_TIME");

    $query = <<"EOQ";
UPDATE otfr_request_stats
SET ors_pod_retr_start_time = '$REQ_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", "otfr_request_stats Update FAILED for $REQUEST\n");
    }
    DoDBIclose($db);
}
1;
