Index: branches/backtrack/ippTools/src/pxchip.c
===================================================================
--- branches/backtrack/ippTools/src/pxchip.c	(revision 13994)
+++ branches/backtrack/ippTools/src/pxchip.c	(revision 13996)
@@ -2,5 +2,5 @@
  * pxchip.c
  *
- * Copyright (C) 2006  Joshua Hoblitt
+ * Copyright (C) 2007  Joshua Hoblitt
  *
  * This program is free software; you can redistribute it and/or modify it
@@ -54,2 +54,73 @@
     return true;
 }
+
+
+bool pxchipQueueByExpTag(pxConfig *config,
+                         psString exp_tag,
+                         psString workdir,
+                         psString label,
+                         psString reduction,
+                         psString expgroup,
+                         psString dvodb)
+{
+    PS_ASSERT_PTR_NON_NULL(config, 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;
+    }
+
+#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 imfiles for the exp_tag
+    if (!p_psDBRunQuery(config->dbh, query, exp_tag)) {
+        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;
+    }
+
+    // point of no return
+    if (!psDBCommit(config->dbh)) {
+        psError(PS_ERR_UNKNOWN, false, "database error");
+        return false;
+    }
+
+    return true;
+}
