Index: trunk/pstamp/scripts/dqueryparse.pl
===================================================================
--- trunk/pstamp/scripts/dqueryparse.pl	(revision 33324)
+++ trunk/pstamp/scripts/dqueryparse.pl	(revision 33380)
@@ -17,4 +17,5 @@
 use Pod::Usage qw( pod2usage );
 use File::Temp qw( tempfile tempdir);
+use POSIX;  # for strftime
 
 use PS::IPP::PStamp::RequestFile qw( :standard );
@@ -98,4 +99,40 @@
 my_die("$request_file is version $extver expecting 1 or 2", $PS_EXIT_PROG_ERROR)
     if ($extver ne 1) and ($extver ne 2);
+
+if ($req_id) {
+    my $command = "$pstamptool -listreq  -name $req_name -not_req_id $req_id";
+    # set verbose to false so that error message about request not found doesn't appear in parse_error.txt
+    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+        run(command => $command, verbose => 0);
+    if ($success) {
+        # -listreq succeeded duplicate request name
+        print STDERR "QUERY_ID $req_name has already been used\n";
+        $command = "$pstamptool -addjob -job_type none -rownum 0 -state stop -fault $PSTAMP_DUP_REQUEST -req_id $req_id";
+        unless ($no_update) {
+            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+                run(command => $command, verbose => $verbose);
+            if (!$success) {
+                my_die("$command failed", $PS_EXIT_UNKNOWN_ERROR);
+            }
+        } else {
+            print STDERR "skipping $command\n";
+        }
+        
+        my $datestr = strftime "%Y%m%d%H%M%S.$req_id", gmtime;
+        $req_name = "ERROR.$datestr";
+    }
+    $command = "$pstamptool -updatereq -req_id $req_id  -set_name $req_name -set_outProduct $product";
+    unless ($no_update) {
+        ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+            run(command => $command, verbose => $verbose);
+        unless ($success) {
+            my_die("$command failed", $PS_EXIT_UNKNOWN_ERROR);
+        }
+    } else {
+        print STDERR "skipping $command\n";
+    }
+    exit (0);
+}
+
 
 
@@ -357,5 +394,4 @@
             my $component = $query{$fpa_id}{COMPONENT_ID}[$i];
             print "Need to UPDATE $stage $stage_id $component from $data_state\n";
-    ####                           my ($req_id, $outdir, $label, $state, $stage, $stage_id, $component, $need_magic, $imagedb) = @_;
             $dep_id = queue_update_run($req_id, $outdir, $label, $data_state, $stage, $stage_id, $component, 0, $imagedb);
         }
@@ -413,9 +449,25 @@
 }
 
-# XXX: flesh this out once we have a request without duplicate ROWNUMS
 foreach my $rownum (keys %faulted_rows ) {
+    my $outputBase = "$outdir/$job_num" . "_";
     my $fault = $faulted_rows{$rownum};
     $fault = $PSTAMP_NO_IMAGE_MATCH if ($fault eq 'no_fault');
     print STDERR "insert faulted job for $rownum: $fault\n";
+    my $command = "$pstamptool -addjob -req_id $req_id -outputBase $outputBase -job_type detect_query -state stop -rownum $rownum -fault $fault";
+    unless ($no_update) {
+        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+            run(command => $command, verbose => $verbose);
+        if ($success) {
+            my $job_id = join "", @$stdout_buf;
+            print "   Queued job: $job_id\n";
+        } else {
+            my $exit_status = $error_code >> 8;
+            $exit_status = $PS_EXIT_UNKNOWN_ERROR unless $exit_status;
+            my_die("Unable to perform $command error code: $error_code", $exit_status);
+        }
+    } else {
+        print STDERR "skipping $command\n";
+    }
+    $job_num++;
 }
 
