Index: trunk/ippTools/src/pxchip.c
===================================================================
--- trunk/ippTools/src/pxchip.c	(revision 17148)
+++ trunk/ippTools/src/pxchip.c	(revision 17161)
@@ -2,5 +2,5 @@
  * pxchip.c
  *
- * Copyright (C) 2007  Joshua Hoblitt
+ * Copyright (C) 2007-2008  Joshua Hoblitt
  *
  * This program is free software; you can redistribute it and/or modify it
@@ -57,4 +57,41 @@
 
 
+bool pxchipRunSetStateByQuery(pxConfig *config, psMetadata *where, const char *state)
+{
+    PS_ASSERT_PTR_NON_NULL(config, false);
+    PS_ASSERT_PTR_NON_NULL(state, false);
+
+    // check that state is a valid string value
+    if (!(
+            (strncmp(state, "run", 4) == 0)
+            || (strncmp(state, "stop", 5) == 0)
+            || (strncmp(state, "reg", 4) == 0)
+        )
+    ) {
+        psError(PS_ERR_UNKNOWN, false,
+                "invalid chipRun state: %s", state);
+        return false;
+    }
+
+    psString query = psStringCopy("UPDATE chipRun JOIN rawExp USING(exp_id) SET state = '%s'");
+
+    if (where) {
+        psString whereClause = psDBGenerateWhereSQL(where, NULL);
+        psStringAppend(&query, " %s", whereClause);
+        psFree(whereClause);
+    }
+
+    if (!p_psDBRunQuery(config->dbh, query, state)) {
+        psFree(query);
+        psError(PS_ERR_UNKNOWN, false, "database error");
+        return false;
+    }
+
+    psFree(query);
+
+    return true;
+}
+
+
 bool pxchipRunSetLabel(pxConfig *config, psS64 chip_id, const char *label)
 {
@@ -73,13 +110,38 @@
 
 
+bool pxchipRunSetLabelByQuery(pxConfig *config, psMetadata *where, const char *label)
+{
+    PS_ASSERT_PTR_NON_NULL(config, false);
+    // note label == NULL should be explicitly allowed
+ 
+    psString query = psStringCopy("UPDATE chipRun JOIN rawExp USING(exp_id) SET label = '%s'");
+
+    if (where) {
+        psString whereClause = psDBGenerateWhereSQL(where, NULL);
+        psStringAppend(&query, " %s", whereClause);
+        psFree(whereClause);
+    }
+
+    if (!p_psDBRunQuery(config->dbh, query, label)) {
+        psFree(query);
+        psError(PS_ERR_UNKNOWN, false, "database error");
+        return false;
+    }
+
+    psFree(query);
+
+    return true;
+}
+
+
 psS64 pxchipQueueByExpTag(pxConfig *config,
                          psS64 exp_id,
-                         char *workdir,
-                         char *label,
-                         char *reduction,
-                         char *expgroup,
-                         char *dvodb,
-                         char *tess_id,
-                         char *end_stage)
+                         const char *workdir,
+                         const char *label,
+                         const char *reduction,
+                         const char *expgroup,
+                         const char *dvodb,
+                         const char *tess_id,
+                         const char *end_stage)
 {
     PS_ASSERT_PTR_NON_NULL(config, false);
