Index: trunk/ippTools/src/chiptool.c
===================================================================
--- trunk/ippTools/src/chiptool.c	(revision 23873)
+++ trunk/ippTools/src/chiptool.c	(revision 23919)
@@ -125,5 +125,5 @@
     psMetadata *where = psMetadataAlloc();
     pxchipGetSearchArgs (config, where); // rawExp only
-    PXOPT_COPY_STR(config->args, where, "-label", "rawExp.label", "LIKE");
+    pxAddLabelSearchArgs (config, where, "-label", "newExp.label", "LIKE");
 
     // psListLength(where->list) is at least 1 because exp_type defaults to "object"
@@ -219,18 +219,54 @@
     }
 
+
+# define GET_VALUE(PTYPE,CTYPE,VALUE,NAME) 				\
+    PTYPE VALUE;							\
+    { bool status;							\
+	VALUE = psMetadataLookup##CTYPE(&status, md, NAME);		\
+	if (!status) {							\
+	    psError(PS_ERR_UNKNOWN, false, "failed to lookup value for %s", NAME); \
+	    psFree(output);						\
+	    return false;						\
+	} }
+
     // loop over our list of exp_ids
     for (long i = 0; i < psArrayLength(output); i++) {
         psMetadata *md = output->data[i];
 
-        bool status;
-        psS64 exp_id = psMetadataLookupS64(&status, md, "exp_id");
-        if (!status) {
-            psError(PS_ERR_UNKNOWN, false, "failed to lookup value for exp_id");
+        rawExpRow *row = rawExpObjectFromMetadata(md);
+        if (!row) {
+            psError(PS_ERR_UNKNOWN, false, "failed to convert metadata into chipRun");
             psFree(output);
             return false;
         }
-        //
+
+        GET_VALUE (psS64,    S64, exp_id,      	 "exp_id");
+        GET_VALUE (psString, Str, raw_workdir, 	 "workdir");
+        GET_VALUE (psString, Str, raw_label,   	 "label");
+        GET_VALUE (psString, Str, raw_reduction, "reduction");
+        // GET_VALUE (psString, Str, raw_expgroup,  "expgroup");
+        GET_VALUE (psString, Str, raw_dvodb,     "dvodb");
+        GET_VALUE (psString, Str, raw_tess_id,   "tess_id");
+        GET_VALUE (psString, Str, raw_end_stage, "end_stage");
+
+        if (!row->exp_id) {
+            psError(PS_ERR_UNKNOWN, false, "failed to find value for exp_id");
+            psFree(output);
+            return false;
+        }
+
         // queue the exp
-        if (!pxchipQueueByExpTag(config, exp_id, workdir, label, reduction, expgroup, dvodb, tess_id, end_stage)) {
+        if (!pxchipQueueByExpTag(config, 
+				 exp_id, 
+				 workdir     ? workdir   : raw_workdir,
+				 label       ? label     : raw_label,
+				 reduction   ? reduction : raw_reduction,
+				 // expgroup    ? expgroup  : raw_expgroup,
+				 // XXX how does expgroup get defined?
+				 expgroup,
+				 dvodb       ? dvodb     : raw_dvodb,
+				 tess_id     ? tess_id   : raw_tess_id,
+				 end_stage   ? end_stage : raw_end_stage
+				 )) {
             if (!psDBRollback(config->dbh)) {
                 psError(PS_ERR_UNKNOWN, false, "database error");
@@ -260,4 +296,5 @@
     pxchipGetSearchArgs (config, where); // rawExp, chipRun
     PXOPT_COPY_S64(config->args,  where, "-chip_id", "chipRun.chip_id", "==");
+    // we only allow a single label to match (do not use pxAddLabelSearchArgs here)
     PXOPT_COPY_STR(config->args,  where, "-label",   "chipRun.label",   "==");
     PXOPT_COPY_STR(config->args,  where, "-state",   "chipRun.state",   "==");
@@ -312,5 +349,5 @@
     pxchipGetSearchArgs (config, where); //chipRun, rawExp
     PXOPT_COPY_S64(config->args, where, "-chip_id", "chipRun.chip_id", "==");
-    PXOPT_COPY_STR(config->args, where, "-label", "chipRun.label", "==");
+    pxAddLabelSearchArgs (config, where, "-label", "chipRun.label", "==");
 
     psString query = pxDataGet("chiptool_pendingimfile.sql");
@@ -563,5 +600,5 @@
     PXOPT_COPY_STR(config->args, where, "-class_id", "chipProcessedImfile.class_id", "==");
     PXOPT_COPY_STR(config->args, where, "-reduction", "chipRun.reduction", "==");
-    PXOPT_COPY_STR(config->args, where, "-label", "chipRun.label", "LIKE");
+    pxAddLabelSearchArgs (config, where, "-label", "chipRun.label", "LIKE");
     PXOPT_COPY_S32(config->args, where, "-magicked", "chipRun.magicked", "==");
 
@@ -639,5 +676,6 @@
     PXOPT_COPY_S64(config->args, where, "-chip_id", "chipRun.chip_id", "==");
     PXOPT_COPY_STR(config->args, where, "-class_id", "chipProcessedImfile.class_id", "==");
-    PXOPT_COPY_STR(config->args, where, "-label", "chipRun.label", "LIKE");
+    // require a single label 
+    PXOPT_COPY_STR(config->args, where, "-label", "chipRun.label", "==");
     PXOPT_COPY_STR(config->args, where, "-reduction", "chipRun.reduction", "==");
     PXOPT_COPY_S16(config->args, where, "-fault", "chipProcessedImfile.fault", "==");
@@ -865,5 +903,5 @@
 
     psMetadata *where = psMetadataAlloc();
-    PXOPT_COPY_STR(config->args, where, "-label", "label", "==");
+    pxAddLabelSearchArgs (config, where, "-label", "label", "==");
 
     psString query = pxDataGet("chiptool_pendingcleanuprun.sql");
@@ -929,5 +967,5 @@
         PXOPT_COPY_S64(config->args, where, "-chip_id", "chip_id", "==");
     }
-    PXOPT_COPY_STR(config->args, where, "-label", "label", "==");
+    pxAddLabelSearchArgs (config, where, "-label", "label", "==");
 
     psString query = pxDataGet("chiptool_pendingcleanupimfile.sql");
@@ -1057,5 +1095,5 @@
 
     psMetadata *where = psMetadataAlloc();
-    PXOPT_COPY_STR(config->args, where, "-label", "label", "==");
+    pxAddLabelSearchArgs (config, where, "-label", "label", "==");
     PXOPT_COPY_STR(config->args, where, "-state", "state", "==");
 
@@ -1118,5 +1156,5 @@
 
     psMetadata *where = psMetadataAlloc();
-    PXOPT_COPY_STR(config->args, where, "-label", "label", "==");
+    pxAddLabelSearchArgs (config, where, "-label", "label", "==");
 
     // look for completed chipPendingExp
