Index: trunk/ippTools/src/addtool.c
===================================================================
--- trunk/ippTools/src/addtool.c	(revision 25299)
+++ trunk/ippTools/src/addtool.c	(revision 25789)
@@ -106,7 +106,8 @@
 
     psMetadata *where = psMetadataAlloc();
-    pxaddGetSearchArgs (config, where);
-    pxAddLabelSearchArgs (config, where, "-label", "addRun.label", "==");
-    PXOPT_COPY_STR(config->args, where, "-reduction", "addRun.reduction", "==");
+    pxcamGetSearchArgs (config, where);
+    PXOPT_COPY_S64(config->args, where,  "-cam_id",    "camRun.cam_id", "==");
+    pxAddLabelSearchArgs (config, where, "-label",     "camRun.label", "==");
+    PXOPT_COPY_STR(config->args, where,  "-reduction", "camRun.reduction", "==");
 
     if (!psListLength(where->list) &&
@@ -121,4 +122,6 @@
     PXOPT_LOOKUP_STR(reduction, config->args, "-set_reduction", false, false);
     PXOPT_LOOKUP_STR(dvodb, config->args, "-set_dvodb", false, false);
+    PXOPT_LOOKUP_BOOL(pretend, config->args, "-pretend", false);
+    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
 
     // find the cam_id of all the exposures that we want to queue up.
@@ -130,5 +133,5 @@
     }
 
-    // use psDBGenerateWhereSQL because the SQL yields an intermediate table
+    // use psDBGenerateWhereConditionSQL because the SQL ends in a WHERE
     if (where && psListLength(where->list)) {
         psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
@@ -136,5 +139,4 @@
         psFree(whereClause);
     }
-
     psFree(where);
 
@@ -153,4 +155,15 @@
     if (!psArrayLength(output)) {
         psTrace("addtool", PS_LOG_INFO, "no rows found");
+        psFree(output);
+        return true;
+    }
+
+    if (pretend) {
+        // negative simple so the default is true
+        if (!ippdbPrintMetadatas(stdout, output, "addRun", !simple)) {
+            psError(PS_ERR_UNKNOWN, false, "failed to print array");
+            psFree(output);
+            return false;
+        }
         psFree(output);
         return true;
@@ -175,5 +188,5 @@
         psMetadata *md = output->data[i];
 
-        addRunRow *row = addRunObjectFromMetadata(md);
+        camRunRow *row = camRunObjectFromMetadata(md);
         if (!row) {
             psError(PS_ERR_UNKNOWN, false, "failed to convert metadata into addRun");
@@ -218,6 +231,8 @@
 
     psMetadata *where = psMetadataAlloc();
-    pxaddGetSearchArgs (config, where);
     PXOPT_COPY_S64(config->args, where, "-add_id",    "addRun.add_id", "==");
+    PXOPT_COPY_S64(config->args, where, "-cam_id",    "camRun.cam_id", "==");
+    pxcamGetSearchArgs (config, where); // most search arguments based on camera
+
     PXOPT_COPY_STR(config->args, where, "-label",     "addRun.label", "==");
     PXOPT_COPY_STR(config->args, where, "-state",     "addRun.state", "==");
@@ -267,6 +282,7 @@
 
     psMetadata *where = psMetadataAlloc();
-    pxaddGetSearchArgs (config, where);
     PXOPT_COPY_S64(config->args, where, "-add_id",    "addRun.add_id", "==");
+    PXOPT_COPY_S64(config->args, where, "-cam_id",    "camRun.cam_id", "==");
+    pxcamGetSearchArgs (config, where);
     pxAddLabelSearchArgs (config, where, "-label", "addRun.label", "==");
     PXOPT_COPY_STR(config->args, where, "-reduction", "addRun.reduction", "==");
@@ -325,62 +341,4 @@
 }
 
-/* static bool pendingimfileMode(pxConfig *config) */
-/* { */
-/*     PS_ASSERT_PTR_NON_NULL(config, false); */
-
-/*     psMetadata *where = psMetadataAlloc(); */
-/*     pxaddGetSearchArgs (config, where); */
-/*     PXOPT_COPY_S64(config->args, where, "-add_id",    "addRun.add_id",                "=="); */
-/*     pxAddLabelSearchArgs (config, where, "-label",    "addRun.label",                 "=="); */
-/*     PXOPT_COPY_STR(config->args, where, "-reduction", "addRun.reduction",             "=="); */
-/*     PXOPT_COPY_S64(config->args, where, "-chip_id",   "addRun.chip_id",              "=="); */
-/*     PXOPT_COPY_STR(config->args, where, "-class_id",  "addProcessedExp.class_id", "=="); */
-
-/*     PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); */
-
-/*     psString query = pxDataGet("addtool_find_pendingimfile.sql"); */
-/*     if (!query) { */
-/*         psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); */
-/*         return false; */
-/*     } */
-
-/*     // use psDBGenerateWhereSQL because the SQL yields an intermediate table */
-/*     if (psListLength(where->list)) { */
-/*         psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); */
-/*         psStringAppend(&query, " AND %s", whereClause); */
-/*         psFree(whereClause); */
-/*     } */
-/*     psFree(where); */
-
-/*     if (!p_psDBRunQuery(config->dbh, query)) { */
-/*         psError(PS_ERR_UNKNOWN, false, "database error"); */
-/*         psFree(query); */
-/*         return false; */
-/*     } */
-/*     psFree(query); */
-
-/*     psArray *output = p_psDBFetchResult(config->dbh); */
-/*     if (!output) { */
-/*         psError(PS_ERR_UNKNOWN, false, "database error"); */
-/*         return false; */
-/*     } */
-/*     if (!psArrayLength(output)) { */
-/*         psTrace("addtool", PS_LOG_INFO, "no rows found"); */
-/*         psFree(output); */
-/*         return true; */
-/*     } */
-
-/*     // negate simple so the default is true */
-/*     if (!ippdbPrintMetadatas(stdout, output, "addProcessedExp", !simple)) { */
-/*         psError(PS_ERR_UNKNOWN, false, "failed to print array"); */
-/*         psFree(output); */
-/*         return false; */
-/*     } */
-
-/*     psFree(output); */
-
-/*     return true; */
-/* } */
-
 static bool addprocessedexpMode(pxConfig *config)
 {
@@ -392,9 +350,6 @@
     // optional
     PXOPT_LOOKUP_F32(dtime_addstar, config->args,  "-dtime_addstar", false, false);
-
     PXOPT_LOOKUP_S32(n_stars, config->args,        "-n_stars", false, false);
-
     PXOPT_LOOKUP_STR(path_base, config->args, "-path_base", false, false);
-
     PXOPT_LOOKUP_S64(magicked, config->args, "-magicked", false, false);
 
@@ -469,38 +424,5 @@
         return false;
     }
-
-    // NULL for end_stage means go as far as possible
-    // EAM : skip here if fault != 0
-    // Also, we can run fake even if tess_id is not defined
-/*     if (fault || (pendingRow->end_stage && psStrcasestr(pendingRow->end_stage, "add"))) { */
-/*         psFree(row); */
-/*         psFree(pendingRow); */
-/*         if (!psDBCommit(config->dbh)) { */
-/*             psError(PS_ERR_UNKNOWN, false, "database error"); */
-/*             return false; */
-/*         } */
-/*         return true; */
-/*     } */
     psFree(row);
-    // else continue on...
-
-/*     if (!pxfakeQueueByAddID(config, */
-/*             pendingRow->add_id, */
-/*             pendingRow->workdir, */
-/*             pendingRow->label, */
-/*             pendingRow->reduction, */
-/*             pendingRow->expgroup, */
-/*             pendingRow->dvodb, */
-/*             pendingRow->tess_id, */
-/*             pendingRow->end_stage */
-/*     )) { */
-/*         // rollback */
-/*         if (!psDBRollback(config->dbh)) { */
-/*             psError(PS_ERR_UNKNOWN, false, "database error"); */
-/*         } */
-/*         psError(PS_ERR_UNKNOWN, false, "failed to queue new fakeRun"); */
-/*         psFree(pendingRow); */
-/*         return false; */
-/*     } */
     psFree(pendingRow);
 
@@ -524,6 +446,7 @@
     // generate restrictions
     psMetadata *where = psMetadataAlloc();
-    pxaddGetSearchArgs (config, where);
     PXOPT_COPY_S64(config->args, where, "-add_id",    "addRun.add_id",    "==");
+    PXOPT_COPY_S64(config->args, where, "-cam_id",    "camRun.cam_id",    "==");
+    pxcamGetSearchArgs (config, where);
     pxAddLabelSearchArgs (config, where, "-label",    "addRun.label",     "==");
     PXOPT_COPY_STR(config->args, where, "-reduction", "addRun.reduction", "==");
@@ -613,9 +536,9 @@
 
     psMetadata *where = psMetadataAlloc();
-    pxaddGetSearchArgs (config, where);
     PXOPT_COPY_S64(config->args, where, "-add_id",    "addRun.add_id",         "==");
+    PXOPT_COPY_S64(config->args, where, "-cam_id",    "camRun.cam_id",         "==");
+    pxcamGetSearchArgs (config, where);
     pxAddLabelSearchArgs (config, where, "-label",    "addRun.label",     "==");
     PXOPT_COPY_STR(config->args, where, "-reduction", "addRun.reduction",      "==");
-/*     PXOPT_COPY_S16(config->args, where, "-fault", "addProcessedExp.fault", "=="); */
 
     if (!psListLength(where->list) && !psMetadataLookupBool(NULL, config->args, "-all")) {
@@ -710,6 +633,4 @@
     PXOPT_COPY_S64(config->args, where, "-add_id",   "add_id",   "==");
     PXOPT_COPY_S64(config->args, where, "-cam_id",  "cam_id",  "==");
-/*     PXOPT_COPY_STR(config->args, where, "-class",    "class",    "=="); */
-/*     PXOPT_COPY_STR(config->args, where, "-class_id", "class_id", "=="); */
 
     if (!pxSetFaultCode(config->dbh, "addProcessedExp", where, fault)) {
@@ -776,5 +697,4 @@
     return true;
 }
-
 
 static bool unblockMode(pxConfig *config)
