Index: branches/tap_branches/ippTools/src/pxchip.c
===================================================================
--- branches/tap_branches/ippTools/src/pxchip.c	(revision 25900)
+++ branches/tap_branches/ippTools/src/pxchip.c	(revision 27838)
@@ -96,5 +96,5 @@
     PXOPT_COPY_STR(config->args, where, "-exp_type", "rawExp.exp_type", "==");
     PXOPT_COPY_STR(config->args, where, "-filelevel", "rawExp.filelevel", "==");
-    PXOPT_COPY_STR(config->args, where, "-filter", "rawExp.filter", "==");
+    PXOPT_COPY_STR(config->args, where, "-filter", "rawExp.filter", "LIKE");
     PXOPT_COPY_F64(config->args, where, "-airmass_min", "rawExp.airmass", ">=");
     PXOPT_COPY_F64(config->args, where, "-airmass_max", "rawExp.airmass", "<");
@@ -125,9 +125,9 @@
     PXOPT_COPY_F32(config->args, where, "-sun_angle_max", "rawExp.sun_angle", "<");
     PXOPT_COPY_STR(config->args, where, "-comment", "rawExp.comment", "LIKE");
-    PXOPT_COPY_STR(config->args, where, "-obs_mode", "rawExp.obs_mode", "==");
-    return true;
-}
-
-bool pxchipRunSetState(pxConfig *config, psS64 chip_id, const char *state, const bool magicked)
+    PXOPT_COPY_STR(config->args, where, "-obs_mode", "rawExp.obs_mode", "LIKE");
+    return true;
+}
+
+bool pxchipRunSetState(pxConfig *config, psS64 chip_id, const char *state, const psS64 magicked)
 {
     PS_ASSERT_PTR_NON_NULL(config, false);
@@ -140,5 +140,5 @@
     }
 
-    char *query = "UPDATE chipRun SET state = '%s', magicked = %d WHERE chip_id = %" PRId64;
+    char *query = "UPDATE chipRun SET state = '%s', magicked = %" PRId64 " WHERE chip_id = %" PRId64;
     if (!p_psDBRunQueryF(config->dbh, query, state, magicked, chip_id)) {
         psError(PS_ERR_UNKNOWN, false,
@@ -174,4 +174,9 @@
 
     psString query = psStringCopy("UPDATE chipRun JOIN rawExp USING(exp_id) SET state = '%s'");
+
+    if (!strcmp(state, "cleaned") || !strcmp(state, "purged")) {
+        // if magicked is non-zero set it to -1
+        psStringAppend(&query, ", chipRun.magicked = IF(chipRun.magicked = 0, 0, -1)");
+    }
 
     if (where && psListLength(where->list) > 0) {
@@ -213,5 +218,5 @@
 /*     } */
 
-    psString query = psStringCopy("UPDATE chipProcessedImfile JOIN chipRun USING(chip_id) JOIN rawExp ON chipRun.exp_id = rawExp.exp_id SET state = '%s'");
+    psString query = psStringCopy("UPDATE chipProcessedImfile JOIN chipRun USING(chip_id) JOIN rawExp ON chipRun.exp_id = rawExp.exp_id SET data_state = '%s'");
 
     if (where && psListLength(where->list) > 0) {
@@ -219,4 +224,7 @@
         psStringAppend(&query, " %s", whereClause);
         psFree(whereClause);
+    } else {
+        psError(PS_ERR_UNKNOWN, true, "search parameters are required");
+        return false;
     }
 
