Index: branches/backtrack/ippTools/src/chipqueue.c
===================================================================
--- branches/backtrack/ippTools/src/chipqueue.c	(revision 13938)
+++ branches/backtrack/ippTools/src/chipqueue.c	(revision 13990)
@@ -23,5 +23,4 @@
 
 #include "pxtools.h"
-#include "pxdata.h"
 #include "chiptool.h"
 
@@ -30,5 +29,5 @@
                      psString workdir,
                      psString label,
-                     psString recipe,
+                     psString reduction,
                      psString expgroup,
                      psString dvodb)
@@ -36,34 +35,44 @@
     PS_ASSERT_PTR_NON_NULL(config, false);
 
-    // load the SQL to enqueue our exp_tags from disk once
-    static psString queuerawexp_query = NULL;
-    if (!queuerawexp_query) {
-        queuerawexp_query = pxDataGet("chiptool_queuerawexp.sql");
-        psMemSetPersistent(queuerawexp_query, true);
-        if (!queuerawexp_query) {
-            psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
-            return false;
+    // start a transaction
+    if (!psDBTransaction(config->dbh)) {
+        psError(PS_ERR_UNKNOWN, false, "database error");
+        return false;
+    }
+    
+    // create a chipRun
+    if (!chipRunInsert(config->dbh,
+            0x0,
+            "run",      // state                
+            workdir,
+            "dirty",    // workdir_state
+            label,
+            reduction,
+            expgroup,
+            dvodb)
+    ) {
+        // rollback
+        if (!psDBRollback(config->dbh)) {
+            psError(PS_ERR_UNKNOWN, false, "database error");
         }
+        psError(PS_ERR_UNKNOWN, false, "database error");
+        return false;
     }
 
-    static psString queuerawimfile_query = NULL;
-    if (!queuerawimfile_query) {
-        queuerawimfile_query = pxDataGet("chiptool_queuerawimfile.sql");
-        psMemSetPersistent(queuerawimfile_query, true);
-        if (!queuerawexp_query) {
-            psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
-            return false;
-        }
+#if 0
+    // get the chip_id
+    long chip_id = psDBLastInsertID(config->dbh);
+#endif
+
+    // populate the chipPendingImfile table from rawImfile based on exp_tag,
+    // where the coresponding newExp.state entry is set to stop
+    psString query = pxDataGetCached("chiptool_queuerawimfile.sql");
+    if (!query) {
+        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
+        return false;
     }
 
-    // queue the exp
-    if (!p_psDBRunQuery(config->dbh, queuerawexp_query,
-                workdir  ? workdir  : "NULL",
-                label    ? label    : "NULL",
-                recipe   ? recipe   : "NULL",
-                expgroup ? expgroup : "NULL",
-                dvodb    ? dvodb    : "NULL",
-                exp_tag
-    )) {
+    // queue the imfiles for the exp_tag
+    if (!p_psDBRunQuery(config->dbh, query, exp_tag)) {
         psError(PS_ERR_UNKNOWN, false, "database error");
         return false;
@@ -77,14 +86,7 @@
     }
 
-    // queue the imfiles for the exp we just queued
-    if (!p_psDBRunQuery(config->dbh, queuerawimfile_query)) {
+    // point of no return
+    if (!psDBCommit(config->dbh)) {
         psError(PS_ERR_UNKNOWN, false, "database error");
-        return false;
-    }
-
-    // just to be safe, we should have changed at least one row
-    if (psDBAffectedRows(config->dbh) < 1) {
-        psError(PS_ERR_UNKNOWN, false,
-                "no rows affected - should have changed at least one row");
         return false;
     }
