Index: /trunk/ippTools/src/stacktool.c
===================================================================
--- /trunk/ippTools/src/stacktool.c	(revision 11982)
+++ /trunk/ippTools/src/stacktool.c	(revision 11983)
@@ -39,5 +39,5 @@
 static bool sumscfileMode(pxConfig *config);
 
-static bool setp6RunState(pxConfig *config, const char *p4_id, const char *state);
+static bool setp6RunState(pxConfig *config, const char *p6_id, const char *state);
 
 # define MODECASE(caseName, func) \
@@ -104,4 +104,24 @@
     }
 
+    psString skycell_id = psMetadataLookupStr(&status, config->args, "-skycell_id");
+    if (!status) {
+        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -skycell_id");
+        return false;
+    }
+    if (!skycell_id) {
+        psError(PS_ERR_UNKNOWN, true, "-skycell_id is required");
+        return false;
+    }
+
+    psString tess_id = psMetadataLookupStr(&status, config->args, "-tess_id");
+    if (!status) {
+        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -tess_id");
+        return false;
+    }
+    if (!tess_id) {
+        psError(PS_ERR_UNKNOWN, true, "-tess_id is required");
+        return false;
+    }
+
     psTime *registered = NULL;
     {
@@ -124,5 +144,7 @@
             workdir,
             NULL,       // dvodb
-            registered
+            registered,
+            skycell_id,
+            tess_id
     );
     psFree(registered);
@@ -223,23 +245,4 @@
     }
 
-    psString skycell_id = psMetadataLookupStr(&status, config->args, "-skycell_id");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -skycell_id");
-        return false;
-    }
-    if (!skycell_id) {
-        psError(PS_ERR_UNKNOWN, true, "-skycell_id is required");
-        return false;
-    }
-
-    psString tess_id = psMetadataLookupStr(&status, config->args, "-tess_id");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -tess_id");
-        return false;
-    }
-    if (!tess_id) {
-        psError(PS_ERR_UNKNOWN, true, "-tess_id is required");
-        return false;
-    }
 
     // XXX need to validate the p4_id here
@@ -248,7 +251,5 @@
     if (!p6InputScfileInsert(config->dbh, 
             (psS32)atoi(p6_id),
-            (psS32)atoi(p4_id),
-            skycell_id,
-            tess_id
+            (psS32)atoi(p4_id)
         )) {
         psError(PS_ERR_UNKNOWN, false, "database error");
@@ -279,7 +280,7 @@
         "   USING(p6_id)\n"
         " JOIN p4Scfile\n"
-        "   ON p6InputScfile.p4_id = p4Scfile.p4_id\n"
-        "   AND p6InputScfile.skycell_id = p4Scfile.skycell_id\n"
-        "   AND p6InputScfile.tess_id = p4Scfile.tess_id\n"
+        "   ON  p6InputScfile.p4_id = p4Scfile.p4_id\n"
+        "   AND p6Run.skycell_id    = p4Scfile.skycell_id\n"
+        "   AND p6Run.tess_id       = p4Scfile.tess_id\n"
         " WHERE\n"
         "   p6Run.state = 'run'\n" 
@@ -454,24 +455,4 @@
     }
 
-    psString skycell_id = psMetadataLookupStr(&status, config->args, "-skycell_id");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -skycell_id");
-        return false;
-    }
-    if (!skycell_id) {
-        psError(PS_ERR_UNKNOWN, true, "-skycell_id is required");
-        return false;
-    }
-
-    psString tess_id = psMetadataLookupStr(&status, config->args, "-tess_id");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -tess_id");
-        return false;
-    }
-    if (!tess_id) {
-        psError(PS_ERR_UNKNOWN, true, "-tess_id is required");
-        return false;
-    }
-
     psString uri = psMetadataLookupStr(&status, config->args, "-uri");
     if (!status) {
@@ -494,4 +475,9 @@
     if (!status) {
         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -bg_mean_stdev");
+        return false;
+    }
+
+    if (!psDBTransaction(config->dbh)) {
+        psError(PS_ERR_UNKNOWN, false, "database error");
         return false;
     }
@@ -502,10 +488,25 @@
     if (!p6SumScfileInsert(config->dbh, 
             (psS32)atoi(p6_id),
-            skycell_id,
-            tess_id,
             uri,
             bg,
             bg_mean_stdev
         )) {
+        if (!psDBRollback(config->dbh)) {
+            psError(PS_ERR_UNKNOWN, false, "database error");
+        }
+        psError(PS_ERR_UNKNOWN, false, "database error");
+        return false;
+    }
+
+    if (setp6RunState(config, p6_id, "stop")) {
+        if (!psDBRollback(config->dbh)) {
+            psError(PS_ERR_UNKNOWN, false, "database error");
+        }
+        psError(PS_ERR_UNKNOWN, false, "failed to change p6Run's state");
+        return false;
+    }
+
+    // point of no return
+    if (!psDBCommit(config->dbh)) {
         psError(PS_ERR_UNKNOWN, false, "database error");
         return false;
Index: /trunk/ippTools/src/stacktoolConfig.c
===================================================================
--- /trunk/ippTools/src/stacktoolConfig.c	(revision 11982)
+++ /trunk/ippTools/src/stacktoolConfig.c	(revision 11983)
@@ -52,4 +52,8 @@
     psMetadataAddStr(definerunArgs, PS_LIST_TAIL, "-registered",  0,
             "time detrend run was registered", now);
+    psMetadataAddStr(definerunArgs, PS_LIST_TAIL, "-skycell_id",  0,
+            "define skycell ID (required)", NULL);
+    psMetadataAddStr(definerunArgs, PS_LIST_TAIL, "-tess_id",  0,
+            "define tessellation ID (required)", NULL);
     psMetadataAddBool(definerunArgs, PS_LIST_TAIL, "-simple",  0,
             "use the simple output format", false);
@@ -74,8 +78,4 @@
     psMetadataAddStr(addinputscfileArgs, PS_LIST_TAIL, "-p4_id", 0,
             "define p4 ID (required)", NULL);
-    psMetadataAddStr(addinputscfileArgs, PS_LIST_TAIL, "-skycell_id",  0,
-            "define skycell ID (required)", NULL);
-    psMetadataAddStr(addinputscfileArgs, PS_LIST_TAIL, "-tess_id",  0,
-            "define tessellation ID (required)", NULL);
 
     // -inputscfile
@@ -85,8 +85,4 @@
     psMetadataAddStr(inputscfileArgs, PS_LIST_TAIL, "-p4_id", 0,
             "search by p4 ID (required)", NULL);
-    psMetadataAddStr(inputscfileArgs, PS_LIST_TAIL, "-skycell_id",  0,
-            "search by skycell ID (required)", NULL);
-    psMetadataAddStr(inputscfileArgs, PS_LIST_TAIL, "-tess_id",  0,
-            "search by tessellation ID (required)", NULL);
     psMetadataAddU64(inputscfileArgs, PS_LIST_TAIL, "-limit",  0,
             "limit result set to N items", 0);
@@ -100,8 +96,4 @@
     psMetadataAddStr(tosumArgs, PS_LIST_TAIL, "-p4_id", 0,
             "search by p4 ID (required)", NULL);
-    psMetadataAddStr(tosumArgs, PS_LIST_TAIL, "-skycell_id",  0,
-            "search by skycell ID (required)", NULL);
-    psMetadataAddStr(tosumArgs, PS_LIST_TAIL, "-tess_id",  0,
-            "search by tessellation ID (required)", NULL);
     psMetadataAddU64(tosumArgs, PS_LIST_TAIL, "-limit",  0,
             "limit result set to N items", 0);
@@ -113,8 +105,4 @@
     psMetadataAddStr(addsumscfileArgs, PS_LIST_TAIL, "-p6_id", 0,
             "define p4 ID (required)", NULL);
-    psMetadataAddStr(addsumscfileArgs, PS_LIST_TAIL, "-skycell_id",  0,
-            "define skycell ID (required)", NULL);
-    psMetadataAddStr(addsumscfileArgs, PS_LIST_TAIL, "-tess_id",  0,
-            "define tessellation ID (required)", NULL);
     psMetadataAddStr(addsumscfileArgs, PS_LIST_TAIL, "-uri", 0,
             "define URI of file (required)", 0);
@@ -130,8 +118,4 @@
     psMetadataAddStr(sumscfileArgs, PS_LIST_TAIL, "-p4_id", 0,
             "search by p4 ID (required)", NULL);
-    psMetadataAddStr(sumscfileArgs, PS_LIST_TAIL, "-skycell_id",  0,
-            "search by skycell ID (required)", NULL);
-    psMetadataAddStr(sumscfileArgs, PS_LIST_TAIL, "-tess_id",  0,
-            "search by tessellation ID (required)", NULL);
     psMetadataAddU64(sumscfileArgs, PS_LIST_TAIL, "-limit",  0,
             "limit result set to N items", 0);
Index: /trunk/ippTools/src/warptool.c
===================================================================
--- /trunk/ippTools/src/warptool.c	(revision 11982)
+++ /trunk/ippTools/src/warptool.c	(revision 11983)
@@ -909,4 +909,7 @@
             bg_mean_stdev
         )) {
+        if (!psDBRollback(config->dbh)) {
+            psError(PS_ERR_UNKNOWN, false, "database error");
+        }
         psError(PS_ERR_UNKNOWN, false, "database error");
         return false;
@@ -914,4 +917,7 @@
 
     if (!p4CompletedRuns(config)) {
+        if (!psDBRollback(config->dbh)) {
+            psError(PS_ERR_UNKNOWN, false, "database error");
+        }
         psError(PS_ERR_UNKNOWN, false, "database error");
         return false;
