Index: trunk/ippTools/src/pstamptool.c
===================================================================
--- trunk/ippTools/src/pstamptool.c	(revision 16942)
+++ trunk/ippTools/src/pstamptool.c	(revision 16957)
@@ -35,4 +35,5 @@
 static bool moddatastoreMode(pxConfig *config);
 static bool addReqMode(pxConfig *config);
+static bool listReqMode(pxConfig *config);
 static bool pendingReqMode(pxConfig *config);
 static bool processedReqMode(pxConfig *config);
@@ -65,4 +66,5 @@
         MODECASE(PSTAMPTOOL_MODE_MODDATASTORE, moddatastoreMode);
         MODECASE(PSTAMPTOOL_MODE_ADDREQ, addReqMode);
+        MODECASE(PSTAMPTOOL_MODE_LISTREQ, listReqMode);
         MODECASE(PSTAMPTOOL_MODE_PENDINGREQ, pendingReqMode);
         MODECASE(PSTAMPTOOL_MODE_PROCESSEDREQ, processedReqMode);
@@ -254,4 +256,47 @@
 }
 
+#define  MAGIC_STR  "$REQ_ID"
+
+// Replace $REQ_ID with the value of the request id if present in the outFileset
+
+static bool
+updateFilesetID(pxConfig *config, psS64 req_id, psString outFileset)
+{
+    char *magic;
+
+    magic = strcasestr(outFileset, MAGIC_STR);
+    if (magic == NULL) {
+        return true;
+    }
+
+    // find part of the string after the magic
+    char *after = magic + strlen(MAGIC_STR);
+
+    if (*after == 0) {
+        after = NULL;
+    }
+
+    psString converted = NULL;
+    if (magic > outFileset) {
+        int len = magic - outFileset;
+        converted = psStringAlloc(len + 1);
+        strncpy(converted, outFileset, len);
+        converted[len] = 0;
+    }
+
+    psStringAppend(&converted, "%" PRId64, req_id);
+    if (after) {
+        psStringAppend(&converted, after);
+    }
+
+    if (!p_psDBRunQuery(config->dbh, "UPDATE pstampRequest set outFileset = '%s' WHERE req_id = %" PRId64,
+            converted, req_id)) {
+        psError(PS_ERR_UNKNOWN, false, "database error");
+        return false;
+    }
+
+    return true;
+}
+
 static bool addReqMode(pxConfig *config)
 {
@@ -307,4 +352,9 @@
 
     psS64 req_id = psDBLastInsertID(config->dbh);
+    if (!updateFilesetID(config, req_id, outFileset)) {
+        psError(PS_ERR_UNKNOWN, false, "failed to update fileset id\n");
+        return false;
+    }
+
     printf("%" PRId64 "\n", req_id);
 
@@ -334,4 +384,78 @@
         psStringAppend(&query, " AND %s", whereClause);
         psFree(whereClause);
+    }
+
+    // treat limit == 0 as "no limit"
+    if (limit) {
+        psString limitString = psDBGenerateLimitSQL(limit);
+        psStringAppend(&query, " %s", limitString);
+        psFree(limitString);
+    }
+
+    if (!p_psDBRunQuery(config->dbh, query)) {
+        psError(PS_ERR_UNKNOWN, false, "database error");
+        psFree(query);
+        return false;
+    }
+    psFree(query);
+
+    psArray *output = p_psDBFetchResult(config->dbh);
+    if (!output) {
+        psError(PS_ERR_UNKNOWN, false, "database error");
+        return false;
+    }
+    if (!psArrayLength(output)) {
+        psTrace("pstamptool", PS_LOG_INFO, "no rows found");
+        psFree(output);
+        return true;
+    }
+
+    bool simple = false;
+    {
+        bool status = false;
+        simple = psMetadataLookupBool(&status, config->args, "-simple");
+        if (!status) {
+            psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -simple");
+            psFree(output);
+            return false;
+        }
+    }
+
+    // negative simple so the default is true
+    if (!ippdbPrintMetadatas(stdout, output, "pstampRequest", !simple)) {
+        psError(PS_ERR_UNKNOWN, false, "failed to print array");
+        psFree(output);
+        return false;
+    }
+
+    psFree(output);
+
+    return true;
+}
+static bool listReqMode(pxConfig *config)
+{
+    PS_ASSERT_PTR_NON_NULL(config, false);
+
+    bool status = false;
+    psU64 limit = psMetadataLookupU64(&status, config->args, "-limit");
+    if (!status) {
+        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -limit");
+        return false;
+    }
+
+    psString query = NULL;
+
+    psString req_id = psMetadataLookupStr(&status, config->args, "-req_id");
+    
+    if (req_id) {
+        psStringAppend(&query,
+                "SELECT"
+                " *"
+                " FROM pstampRequest"
+                " WHERE req_id = %s", req_id
+            );
+    } else {
+        fprintf(stderr, "req_id must be specified\n");
+        exit (1);
     }
 
Index: trunk/ippTools/src/pstamptool.h
===================================================================
--- trunk/ippTools/src/pstamptool.h	(revision 16942)
+++ trunk/ippTools/src/pstamptool.h	(revision 16957)
@@ -29,4 +29,5 @@
     PSTAMPTOOL_MODE_MODDATASTORE,
     PSTAMPTOOL_MODE_ADDREQ,
+    PSTAMPTOOL_MODE_LISTREQ,
     PSTAMPTOOL_MODE_PENDINGREQ,
     PSTAMPTOOL_MODE_PROCESSEDREQ,
Index: trunk/ippTools/src/pstamptoolConfig.c
===================================================================
--- trunk/ippTools/src/pstamptoolConfig.c	(revision 16942)
+++ trunk/ippTools/src/pstamptoolConfig.c	(revision 16957)
@@ -89,4 +89,13 @@
             "limit result set to N items", 0);
     psMetadataAddBool(pendingreqArgs, PS_LIST_TAIL, "-simple", 0,
+            "use the simple output format", false);
+
+    // -listreq
+    psMetadata *listreqArgs = psMetadataAlloc();
+    psMetadataAddStr(listreqArgs, PS_LIST_TAIL, "-req_id", 0,
+            "define req_id", NULL); 
+    psMetadataAddU64(listreqArgs, PS_LIST_TAIL, "-limit",  0,
+            "limit result set to N items", 0);
+    psMetadataAddBool(listreqArgs, PS_LIST_TAIL, "-simple", 0,
             "use the simple output format", false);
 
@@ -165,4 +174,5 @@
     PXOPT_ADD_MODE("-pendingreq",      "", PSTAMPTOOL_MODE_PENDINGREQ,   pendingreqArgs);
     PXOPT_ADD_MODE("-processedreq",    "", PSTAMPTOOL_MODE_PROCESSEDREQ, processedreqArgs);
+    PXOPT_ADD_MODE("-listreq",         "", PSTAMPTOOL_MODE_LISTREQ,      listreqArgs);
 
     PXOPT_ADD_MODE("-addjob",          "", PSTAMPTOOL_MODE_ADDJOB,       addjobArgs);
