Index: trunk/ippTools/src/chiptool.c
===================================================================
--- trunk/ippTools/src/chiptool.c	(revision 12184)
+++ trunk/ippTools/src/chiptool.c	(revision 12188)
@@ -29,4 +29,5 @@
 #include "pxdata.h"
 #include "chiptool.h"
+#include "camtool.h"
 
 static bool queuerawexpMode(pxConfig *config);
@@ -41,5 +42,4 @@
 static chipProcessedImfileRow *chipPendingToProcessedImfile(pxConfig *config, chipPendingImfileRow *imfile);
 static chipProcessedExpRow *chipPendingToProcessedExp(pxConfig *config, chipPendingExpRow *pendingExp);
-static camPendingExpRow *chipPendingTocamPendingExp(pxConfig *config, chipPendingExpRow *pendingExp);
 static bool chipProcessedCompleteExp(pxConfig *config);
 
@@ -748,53 +748,62 @@
     for (long i = 0; i < psArrayLength(output); i++) {
         psMetadata *row = output->data[i];
+
         // convert metadata into a chipPendingExp object
-        chipPendingExpRow *object = chipPendingExpObjectFromMetadata(row);
-        // do both *Exp type conversion first so we don't insert one and then
-        // have to rollback the change as the 2nd failed
+        chipPendingExpRow *pendingExp = chipPendingExpObjectFromMetadata(row);
+        if (!pendingExp) {
+            psError(PS_ERR_UNKNOWN, false, "failed to convert metadata into chipPendingExp");
+            psFree(output);
+            return false;
+        }
+
         // convert chipPendingExp object into a chipProcesseExp object
-        chipProcessedExpRow *processedExp = chipPendingToProcessedExp(config, object);
+        chipProcessedExpRow *processedExp = chipPendingToProcessedExp(config, pendingExp);
         if (!processedExp) {
             psError(PS_ERR_UNKNOWN, false, "failed to convert chipPendingExp to chipProcessedExp");
-            psFree(object);
-            psFree(output);
-            return false;
-        }
-        // convert chipPendingExp object into a camPendingExp object
-        camPendingExpRow *pendingExp = chipPendingTocamPendingExp(config, object);
-        if (!processedExp) {
-            psError(PS_ERR_UNKNOWN, false, "failed to convert chipPendingExp to camPendingExp");
+            psFree(pendingExp);
+            psFree(output);
+            return false;
+        }
+
+        // delete the chipPendingExp object from the database
+        if (!chipPendingExpDeleteObject(config->dbh, pendingExp)) {
+            // there must be atleast 1 Imfile to get this far
+            psError(PS_ERR_UNKNOWN, false, "database error");
             psFree(processedExp);
-            psFree(object);
-            psFree(output);
-            return false;
-        }
+            psFree(pendingExp);
+            psFree(output);
+            return false;
+        }
+        psFree(pendingExp);
+
         // insert chipProccessedExp object into the database
         if (!chipProcessedExpInsertObject(config->dbh, processedExp)) {
             psError(PS_ERR_UNKNOWN, false, "database error");
             psFree(processedExp);
-            psFree(pendingExp);
-            psFree(object);
-            psFree(output);
-            return false;
-        }
+            psFree(output);
+            return false;
+        }
+
+        // camQueueChipID() can only be run after the chipProcessedExp entry
+        // has been inserted.
+        // queue the chip_id in the camPendingExp table 
+        if (!camQueueChipID(config,
+                    processedExp->chip_id,
+                    processedExp->label,
+                    processedExp->recipe,
+                    processedExp->expgroup,
+                    processedExp->dvodb
+        )) {
+            // rollback
+            if (!psDBRollback(config->dbh)) {
+                psError(PS_ERR_UNKNOWN, false, "database error");
+            }
+            psError(PS_ERR_UNKNOWN, false, "failed to queue camPendingExp");
+            psFree(processedExp);
+            psFree(output);
+            return false;
+        }
+
         psFree(processedExp);
-        // insert camPendingExp object into the database
-        if (!camPendingExpInsertObject(config->dbh, pendingExp)) {
-            psError(PS_ERR_UNKNOWN, false, "database error");
-            psFree(pendingExp);
-            psFree(object);
-            psFree(output);
-            return false;
-        }
-        psFree(pendingExp);
-        // delete the chipPendingExp object from the database
-        if (!chipPendingExpDeleteObject(config->dbh, object)) {
-            // there must be atleast 1 Imfile to get this far
-            psError(PS_ERR_UNKNOWN, false, "database error");
-            psFree(object);
-            psFree(output);
-            return false;
-        }
-        psFree(object);
     }
 
@@ -875,20 +884,7 @@
         pendingExp->guide_id,
         pendingExp->label,
+        pendingExp->recipe,
         pendingExp->expgroup,
         pendingExp->dvodb
     );
 }
-
-
-static camPendingExpRow *chipPendingTocamPendingExp(pxConfig *config, chipPendingExpRow *pendingExp)
-{
-    PS_ASSERT_PTR_NON_NULL(pendingExp, NULL);
-
-    return camPendingExpRowAlloc(
-        0,                      // cam version, assigned by db
-        pendingExp->chip_id,
-        pendingExp->label,
-        pendingExp->expgroup,
-        pendingExp->dvodb
-    );
-}
