Index: trunk/ippTools/src/regtool.c
===================================================================
--- trunk/ippTools/src/regtool.c	(revision 13617)
+++ trunk/ippTools/src/regtool.c	(revision 14018)
@@ -44,5 +44,5 @@
 // static guidePendingExpRow *newToP1PendingExp(newExpRow *newExp);
 //static chipPendingExpRow *newTochipPendingExp(pxConfig *config, newExpRow *newExp);
-//static chipPendingImfileRow *rawImfileTochipPendingImfile(pxConfig *config, psS64 chip_id, rawImfileRow *rawImfile);
+//static chipInputImfileRow *rawImfileTochipInputImfile(pxConfig *config, psS64 chip_id, rawImfileRow *rawImfile);
 
 static rawExpRow *newToRawExp(pxConfig *config, newExpRow *exp);
@@ -282,4 +282,5 @@
                 return false;
             }
+            psFree(object);
             // insert the rawImfile object into the database
             if (!rawImfileInsertObject(config->dbh, imfile)) {
@@ -290,21 +291,8 @@
                 psError(PS_ERR_UNKNOWN, false, "failed to insert row into the database");
                 psFree(imfile);
-                psFree(object);
                 psFree(output);
                 return false;
             }
             psFree(imfile);
-            // remove the neImfile object from the database
-            if (!newImfileDeleteObject(config->dbh, object)) {
-                // rollback
-                if (!psDBRollback(config->dbh)) {
-                    psError(PS_ERR_UNKNOWN, false, "database error");
-                }
-                psError(PS_ERR_UNKNOWN, false, "failed to delete row from the database");
-                psFree(object);
-                psFree(output);
-                return false;
-            }
-            psFree(object);
         }
 
@@ -573,11 +561,9 @@
     }
     if (!psArrayLength(output)) {
-        psTrace("regtool", PS_LOG_INFO, "no rows found");
+        psError(PS_ERR_UNKNOWN, false, "no pending newExp rows found");
         psFree(output);
-        return true;
-    }
-
-    // start a transaction so we don't end up with an exp in both rawExp &
-    // newExp
+        return false;
+    }
+
     if (!psDBTransaction(config->dbh)) {
         psError(PS_ERR_UNKNOWN, false, "database error");
@@ -603,4 +589,5 @@
             return false;
         }
+        psFree(newExp);
 
         // insert the rawExp object into the database
@@ -612,5 +599,4 @@
             psError(PS_ERR_UNKNOWN, false, "database error");
             psFree(rawExp);
-            psFree(newExp);
             psFree(output);
             return false;
@@ -618,26 +604,35 @@
         psFree(rawExp);
 
-        // delete the newExp object from the database
-        if (!newExpDeleteObject(config->dbh, newExp)) {
+        // if this is a detrend image don't put it in the chip queue (and we're
+        // done)
+        if (detrend) {
+            // set the state for the newExp to stop 
+            if (!pxnewExpSetState(config, exp_tag, "stop")) {
+                // rollback
+                if (!psDBRollback(config->dbh)) {
+                    psError(PS_ERR_UNKNOWN, false, "database error");
+                }
+                psError(PS_ERR_UNKNOWN, false, "failed to change newExp.state for exp_tag: %s", exp_tag);
+                psFree(output);
+                return false;
+            }
+            continue;
+        }
+
+
+        // set the state for the newExp to stop
+        if (!pxnewExpSetState(config, exp_tag, "stop")) {
             // rollback
             if (!psDBRollback(config->dbh)) {
                 psError(PS_ERR_UNKNOWN, false, "database error");
             }
-            psError(PS_ERR_UNKNOWN, false, "database error");
-            psFree(newExp);
+            psError(PS_ERR_UNKNOWN, false, "failed to change newExp.state for exp_tag: %s", exp_tag);
             psFree(output);
             return false;
         }
 
-        psFree(newExp);
-
-        // if this is a detrend image don't put it in the chip queue (and we're
-        // done)
-        if (detrend) {
-            continue;
-        }
-
         // insert an entry into the chipPendingExp table
-        if (!chipQueueExpTag(config, exp_tag, NULL, NULL, NULL, NULL, NULL)) {
+        // this can only be run as the newExp's state has been set to stop
+        if (!pxchipQueueByExpTag(config, exp_tag, NULL, NULL, NULL, NULL, NULL)) {
             // rollback
             if (!psDBRollback(config->dbh)) {
@@ -649,5 +644,4 @@
         }
     }
-
     psFree(output);
 
@@ -828,7 +822,7 @@
 
 
-static chipPendingImfileRow *rawImfileTochipPendingImfile(pxConfig *config, psS64 chip_id, rawImfileRow *rawImfile)
-{
-    return chipPendingImfileRowAlloc(
+static chipInputImfileRow *rawImfileTochipInputImfile(pxConfig *config, psS64 chip_id, rawImfileRow *rawImfile)
+{
+    return chipInputImfileRowAlloc(
             chip_id,
             rawImfile->class_id,
