Index: trunk/ippTools/src/pstamptool.c
===================================================================
--- trunk/ippTools/src/pstamptool.c	(revision 16361)
+++ trunk/ippTools/src/pstamptool.c	(revision 16471)
@@ -33,4 +33,5 @@
 static bool adddatastoreMode(pxConfig *config);
 static bool datastoreMode(pxConfig *config);
+static bool moddatastoreMode(pxConfig *config);
 static bool addReqMode(pxConfig *config);
 static bool pendingReqMode(pxConfig *config);
@@ -62,4 +63,5 @@
         MODECASE(PSTAMPTOOL_MODE_ADDDATASTORE, adddatastoreMode);
         MODECASE(PSTAMPTOOL_MODE_DATASTORE, datastoreMode);
+        MODECASE(PSTAMPTOOL_MODE_MODDATASTORE, moddatastoreMode);
         MODECASE(PSTAMPTOOL_MODE_ADDREQ, addReqMode);
         MODECASE(PSTAMPTOOL_MODE_PENDINGREQ, pendingReqMode);
@@ -92,30 +94,7 @@
 static bool adddatastoreMode(pxConfig *config)
 {
-    psError(PS_ERR_UNKNOWN, true, "-adddatastore not implemented yet");
-    return false;
-#ifdef notyet
     PS_ASSERT_PTR_NON_NULL(config, false);
 
     bool status = false;
-    psString camera = psMetadataLookupStr(&status, config->args, "-inst");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -inst");
-        return false;
-    }
-    if (!camera) {
-        psError(PS_ERR_UNKNOWN, true, "-inst is required");
-        return false;
-    }
-
-    psString telescope = psMetadataLookupStr(&status, config->args, "-telescope");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -telescope");
-        return false;
-    }
-    if (!telescope) {
-        psError(PS_ERR_UNKNOWN, true, "-telescope is required");
-        return false;
-    }
-
     psString uri = psMetadataLookupStr(&status, config->args, "-uri");
     if (!status) {
@@ -128,8 +107,10 @@
     }
 
-    if (!pzDataStoreInsert(config->dbh,
-            camera,
-            telescope,
-            uri
+    psString lastFileset = psMetadataLookupStr(&status, config->args, "-last_fileset");
+
+    if (!pstampDataStoreInsert(config->dbh,
+            0,
+            uri,
+            lastFileset
         )) {
         psError(PS_ERR_UNKNOWN, false, "database error");
@@ -138,16 +119,11 @@
 
     return true;
-#endif // notyet
 }
 
 static bool datastoreMode(pxConfig *config)
 {
-    psError(PS_ERR_UNKNOWN, true, "-datastore not implemented yet");
-    return false;
-
-#ifdef notyet
-    PS_ASSERT_PTR_NON_NULL(config, false);
-
-    if (!p_psDBRunQuery(config->dbh, "SELECT * FROM pzDataStore")) {
+    PS_ASSERT_PTR_NON_NULL(config, false);
+
+    if (!p_psDBRunQuery(config->dbh, "SELECT * FROM pstampDataStore")) {
         psError(PS_ERR_UNKNOWN, false, "database error");
         return false;
@@ -176,5 +152,5 @@
 
     // negative simple so the default is true
-    if (!ippdbPrintMetadatas(stdout, output, "pzDataStore", !simple)) {
+    if (!ippdbPrintMetadatas(stdout, output, "pstampDataStore", !simple)) {
         psError(PS_ERR_UNKNOWN, false, "failed to print array");
         psFree(output);
@@ -185,5 +161,48 @@
 
     return true;
-#endif // notyet
+}
+static bool moddatastoreMode(pxConfig *config)
+{
+    bool    status;
+
+    PS_ASSERT_PTR_NON_NULL(config, false);
+
+    psString ds_id = psMetadataLookupStr(&status, config->args, "-ds_id");
+    if (!status) {
+        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -ds_id");
+        return false;
+    }
+    if (!ds_id) {
+        psError(PS_ERR_UNKNOWN, true, "-ds_id is required");
+        return false;
+    }
+    psString lastFileset = psMetadataLookupStr(&status, config->args, "-last_fileset");
+    if (!status) {
+        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -last_fileset");
+        return false;
+    }
+    if (!lastFileset) {
+        psError(PS_ERR_UNKNOWN, true, "-last_fileset is required");
+        return false;
+    }
+
+    char *query ="UPDATE pstampDataStore"
+                 " SET lastFileset = '%s'"
+                 " WHERE ds_id = '%s'";
+
+    if (!p_psDBRunQuery(config->dbh, query, lastFileset, ds_id)) {
+        psError(PS_ERR_UNKNOWN, false, "database error");
+        psFree(query);
+        return false;
+    }
+
+    psU64 affected = psDBAffectedRows(config->dbh);
+    if (affected != 1) {
+        psError(PS_ERR_UNKNOWN, false, "should have affected one row but %" 
+                                        PRIu64 " rows were modified", affected);
+        return false;
+    }
+
+    return true;
 }
 
@@ -204,9 +223,19 @@
     }
 
+    // Data Store ID is optional
+    psString ds_id = psMetadataLookupStr(&status, config->args, "-ds_id");
+    if (!status) {
+        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -ds_id");
+        return false;
+    }
+    if (!ds_id) {
+        ds_id = "0";
+    }
+
     char *query ="INSERT INTO pstampRequest"
-                 " (state, uri)"
-                 " VALUES( 'new', '%s')";
-
-    if (!p_psDBRunQuery(config->dbh, query, uri)) {
+                 " (state, uri, ds_id)"
+                 " VALUES( 'new', '%s', %s)";
+
+    if (!p_psDBRunQuery(config->dbh, query, uri, ds_id)) {
         psError(PS_ERR_UNKNOWN, false, "database error");
         psFree(query);
@@ -595,15 +624,15 @@
         return false;
     }
-    psString jobStatus = psMetadataLookupStr(&status, config->args, "-status");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -status");
-        return false;
-    }
-
-    psString statusStr = NULL;
-    if (!jobStatus) {
-        statusStr = psStringCopy("");
+    psString jobResult = psMetadataLookupStr(&status, config->args, "-result");
+    if (!status) {
+        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -result");
+        return false;
+    }
+
+    psString resultStr = NULL;
+    if (!jobResult) {
+        resultStr = psStringCopy("");
     } else {
-        psStringAppend(&statusStr, ", status = '%s'", jobStatus);
+        psStringAppend(&resultStr, ", result = '%s'", jobResult);
     }
         
@@ -615,10 +644,10 @@
                  " WHERE job_id = '%s'";
 
-    if (!p_psDBRunQuery(config->dbh, query, state, statusStr, job_id)) {
-        psError(PS_ERR_UNKNOWN, false, "database error");
-        psFree(query);
-        return false;
-    }
-    psFree(statusStr);
+    if (!p_psDBRunQuery(config->dbh, query, state, resultStr, job_id)) {
+        psError(PS_ERR_UNKNOWN, false, "database error");
+        psFree(query);
+        return false;
+    }
+    psFree(resultStr);
 
     psU64 affected = psDBAffectedRows(config->dbh);
