Index: branches/cleanup/ippTools/src/camtool.c
===================================================================
--- branches/cleanup/ippTools/src/camtool.c	(revision 18153)
+++ branches/cleanup/ippTools/src/camtool.c	(revision 18357)
@@ -97,26 +97,7 @@
     PS_ASSERT_PTR_NON_NULL(config, NULL);
 
-    PXOPT_LOOKUP_STR(chip_id, config->args, "-chip_id", false, false);
-    PXOPT_LOOKUP_STR(exp_id, config->args, "-exp_id", false, false);
-
     psMetadata *where = psMetadataAlloc();
-    // convert chip_id into a psS64
-    if (chip_id) {
-        if (!psMetadataAddS64(where, PS_LIST_TAIL, "chip_id", 0, "==", (psS64)atoll(chip_id))) {
-            psError(PS_ERR_UNKNOWN, false, "failed to add item chip_id");
-            psFree(where);
-            return false;
-        }
-    }
-
-    // convert exp_id into a psS64
-    if (exp_id) {
-        if (!psMetadataAddS64(where, PS_LIST_TAIL, "exp_id", 0, "==", (psS64)atoll(exp_id))) {
-            psError(PS_ERR_UNKNOWN, false, "failed to add item exp_id");
-            psFree(where);
-            return false;
-        }
-    }
-
+    PXOPT_COPY_S64(config->args, where, "-chip_id", "chip_id", "==");
+    PXOPT_COPY_S64(config->args, where, "-exp_id", "exp_id", "==");
     PXOPT_COPY_STR(config->args, where, "-exp_name", "exp_name", "==");
     PXOPT_COPY_STR(config->args, where, "-inst", "camera", "==");
@@ -165,11 +146,11 @@
     }
 
-    PXOPT_LOOKUP_STR(workdir, config->args, "-set_workdir", true, false);
-    PXOPT_LOOKUP_STR(label, config->args, "-set_label", true, false);
-    PXOPT_LOOKUP_STR(reduction, config->args, "-set_reduction", true, false);
-    PXOPT_LOOKUP_STR(expgroup, config->args, "-set_expgroup", true, false);
-    PXOPT_LOOKUP_STR(dvodb, config->args, "-set_dvodb", true, false);
-    PXOPT_LOOKUP_STR(tess_id, config->args, "-set_tess_id", true, false);
-    PXOPT_LOOKUP_STR(end_stage, config->args, "-set_end_stage", true, false);
+    PXOPT_LOOKUP_STR(workdir, config->args, "-set_workdir", false, false);
+    PXOPT_LOOKUP_STR(label, config->args, "-set_label", false, false);
+    PXOPT_LOOKUP_STR(reduction, config->args, "-set_reduction", false, false);
+    PXOPT_LOOKUP_STR(expgroup, config->args, "-set_expgroup", false, false);
+    PXOPT_LOOKUP_STR(dvodb, config->args, "-set_dvodb", false, false);
+    PXOPT_LOOKUP_STR(tess_id, config->args, "-set_tess_id", false, false);
+    PXOPT_LOOKUP_STR(end_stage, config->args, "-set_end_stage", false, false);
 
     // find the exp_id of all the exposures that we want to queue up.
@@ -182,6 +163,6 @@
 
     if (where && psListLength(where->list)) {
-        psString whereClause = psDBGenerateWhereConditionSQL(where, "");
-        psStringAppend(&query, " AND %s", whereClause);
+        psString whereClause = psDBGenerateWhereSQL(where, NULL);
+        psStringAppend(&query, "%s", whereClause);
         psFree(whereClause);
     }
@@ -236,5 +217,5 @@
                     workdir     ? workdir   : row->workdir,
                     label       ? label     : row->label,
-                    reduction      ? reduction    : row->reduction,
+                    reduction   ? reduction : row->reduction,
                     expgroup    ? expgroup  : row->expgroup,
                     dvodb       ? dvodb     : row->dvodb,
@@ -268,36 +249,8 @@
     PS_ASSERT_PTR_NON_NULL(config, false);
 
-    PXOPT_LOOKUP_STR(cam_id, config->args, "-cam_id", false, false);
-    PXOPT_LOOKUP_STR(chip_id, config->args, "-chip_id", false, false);
-    PXOPT_LOOKUP_STR(exp_id, config->args, "-exp_id", false, false);
-
     psMetadata *where = psMetadataAlloc();
-    // convert cam_id into a psS64
-    if (cam_id) {
-        if (!psMetadataAddS64(where, PS_LIST_TAIL, "cam_id", 0, "==", (psS64)atoll(cam_id))) {
-            psError(PS_ERR_UNKNOWN, false, "failed to add item cam_id");
-            psFree(where);
-            return false;
-        }
-    }
-
-    // convert chip_id into a psS64
-    if (chip_id) {
-        if (!psMetadataAddS64(where, PS_LIST_TAIL, "chip_id", 0, "==", (psS64)atoll(chip_id))) {
-            psError(PS_ERR_UNKNOWN, false, "failed to add item chip_id");
-            psFree(where);
-            return false;
-        }
-    }
-
-    // convert exp_id into a psS64
-    if (exp_id) {
-        if (!psMetadataAddS64(where, PS_LIST_TAIL, "exp_id", 0, "==", (psS64)atoll(exp_id))) {
-            psError(PS_ERR_UNKNOWN, false, "failed to add item exp_id");
-            psFree(where);
-            return false;
-        }
-    }
-
+    PXOPT_COPY_S64(config->args, where, "-cam_id", "cam_id", "==");
+    PXOPT_COPY_S64(config->args, where, "-chip_id", "chip_id", "==");
+    PXOPT_COPY_S64(config->args, where, "-exp_id", "exp_id", "==");
     PXOPT_COPY_STR(config->args, where, "-exp_name", "exp_name", "==");
     PXOPT_COPY_STR(config->args, where, "-inst", "camera", "==");
@@ -421,10 +374,4 @@
     }
 
-    if (!convertIdToStr(output)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to convert id fields into a strings");
-        psFree(output);
-        return false;
-    }
-
     // negate simple so the default is true
     if (!ippdbPrintMetadatas(stdout, output, "camPendingExp", !simple)) {
@@ -475,10 +422,4 @@
     }
 
-    if (!convertIdToStr(output)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to convert id fields into a strings");
-        psFree(output);
-        return false;
-    }
-
     // negate simple so the default is true
     if (!ippdbPrintMetadatas(stdout, output, "chipProcessedImfile", !simple)) {
@@ -498,5 +439,5 @@
 
     // required
-    PXOPT_LOOKUP_STR(cam_id, config->args, "-cam_id", true, false);
+    PXOPT_LOOKUP_S64(cam_id, config->args, "-cam_id", true, false);
     PXOPT_LOOKUP_STR(uri, config->args, "-uri", true, false);
 
@@ -554,5 +495,5 @@
         psMetadata *where = psMetadataAlloc();
         if (cam_id) {
-            if (!psMetadataAddS64(where, PS_LIST_TAIL, "cam_id", 0, "==", (psS64)atoll(cam_id))) {
+            if (!psMetadataAddS64(where, PS_LIST_TAIL, "cam_id", 0, "==", cam_id)) {
                 psError(PS_ERR_UNKNOWN, false, "failed to add item cam_id");
                 psFree(where);
@@ -746,10 +687,4 @@
     }
 
-    if (!convertIdToStr(output)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to convert id fields into a strings");
-        psFree(output);
-        return false;
-    }
-
     // negate simple so the default is true
     if (!ippdbPrintMetadatas(stdout, output, "camProcessedExp", !simple)) {
@@ -769,36 +704,8 @@
     PS_ASSERT_PTR_NON_NULL(config, false);
 
-    PXOPT_LOOKUP_STR(cam_id, config->args, "-cam_id", false, false);
-    PXOPT_LOOKUP_STR(chip_id, config->args, "-chip_id", false, false);
-    PXOPT_LOOKUP_STR(exp_id, config->args, "-exp_id", false, false);
-
     psMetadata *where = psMetadataAlloc();
-    // convert cam_id into a psS64
-    if (cam_id) {
-        if (!psMetadataAddS64(where, PS_LIST_TAIL, "cam_id", 0, "==", (psS64)atoll(cam_id))) {
-            psError(PS_ERR_UNKNOWN, false, "failed to add item cam_id");
-            psFree(where);
-            return false;
-        }
-    }
-
-    // convert chip_id into a psS64
-    if (chip_id) {
-        if (!psMetadataAddS64(where, PS_LIST_TAIL, "chip_id", 0, "==", (psS64)atoll(chip_id))) {
-            psError(PS_ERR_UNKNOWN, false, "failed to add item chip_id");
-            psFree(where);
-            return false;
-        }
-    }
-
-    // convert exp_id into a psS64
-    if (exp_id) {
-        if (!psMetadataAddS64(where, PS_LIST_TAIL, "exp_id", 0, "==", (psS64)atoll(exp_id))) {
-            psError(PS_ERR_UNKNOWN, false, "failed to add item exp_id");
-            psFree(where);
-            return false;
-        }
-    }
-
+    PXOPT_COPY_S64(config->args, where, "-cam_id", "cam_id", "==");
+    PXOPT_COPY_S64(config->args, where, "-chip_id", "chip_id", "==");
+    PXOPT_COPY_S64(config->args, where, "-exp_id", "exp_id", "==");
     PXOPT_COPY_STR(config->args, where, "-exp_name", "exp_name", "==");
     PXOPT_COPY_STR(config->args, where, "-inst", "camera", "==");
@@ -977,10 +884,4 @@
     }
 
-    if (!convertIdToStr(output)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to convert id fields into a strings");
-        psFree(output);
-        return false;
-    }
-
     // negative simple so the default is true
     if (!ippdbPrintMetadatas(stdout, output, "camMask", !simple)) {
