Index: trunk/ippTools/src/pztool.c
===================================================================
--- trunk/ippTools/src/pztool.c	(revision 9735)
+++ trunk/ippTools/src/pztool.c	(revision 9967)
@@ -32,5 +32,5 @@
 static bool pendingMode(pxConfig *config);
 static bool copydoneMode(pxConfig *config);
-static bool summitExpPrint(FILE *stream, summitExpRow *summitExp);
+
 static psArray *pztoolPendingExp(pxConfig *config);
 static psArray *pztoolPendingImfiles(pxConfig *config);
@@ -78,40 +78,58 @@
     PS_ASSERT_PTR_NON_NULL(config, false);
 
-    psArray *summit = summitExpSelectRowObjects(config->dbh,
-        config->where, MAX_ROWS);
-    if (!summit) {
-        psError(PS_ERR_UNKNOWN, false, "no summitExp rows found"); \
-        return false;
-    }
-
-    psArray *new = newExpSelectRowObjects(config->dbh,
-        config->where, MAX_ROWS);
-    if (!new) {
-        psError(PS_ERR_UNKNOWN, false, "no newExp rows found"); \
-    }
-
-    if (new) {
-        for (long i = 0; i < summit->n; i++) {
-            summitExpRow *summitExp = summit->data[i];
-            for (long j = 0; j < summit->n; j++) {
-                newExpRow *newExp = new->data[j];
-                if (strcmp(summitExp->exp_id, newExp->exp_id) == 0) {
-                    psArrayRemoveData(summit, summitExp);
-                    // dec the counter as the array just got shorter
-                    //and we don't want to skip elemnts
-                    i--;
-                    break;
-                }
-            }
-        }
-        psFree(new);
-    }
-
-    for (long i = 0; i < summit->n; i++) {
-        if (!summitExpPrint(stdout, summit->data[i])) {
-            psError(PS_ERR_UNKNOWN, false,"summitExpPrint() failed");
+    psString query = psStringCopy(
+        "SELECT"
+        "    summitExp.*"
+        " FROM summitExp"
+        " LEFT JOIN newExp"
+        "   USING(exp_id, camera, telescope)"
+        " WHERE"
+        "   newExp.exp_id is NULL"
+        "   AND newExp.camera IS NULL"
+        "   AND newExp.telescope IS NULL"
+    );
+
+    if (config->where) {
+        psString whereClause = psDBGenerateWhereConditionSQL(config->where, "newExp");
+        psStringAppend(&query, " AND %s", whereClause);
+        psFree(whereClause);
+    }
+
+    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)) {
+        psError(PS_ERR_UNKNOWN, false, "no newExp rows found");
+        psFree(output);
+        return true;
+    }
+
+    bool simple = false;
+    {
+        bool status = false;
+        simple = psMetadataLookupBool(&status, config->args, "-simple");
+        if (!status) {
+            psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -simple");
             return false;
         }
     }
+
+    // negative simple so the default is true
+    if (!ippdbPrintMetadatas(stdout, output, "newExp", !simple)) {
+        psError(PS_ERR_UNKNOWN, false, "failed to print array");
+        psFree(output);
+        return false;
+    }
+
+    psFree(output);
 
     return true;
@@ -201,20 +219,4 @@
 
     return false;
-}
-
-static bool summitExpPrint(FILE *stream, summitExpRow *summitExp)
-{
-    PS_ASSERT_PTR_NON_NULL(stream, false);
-    PS_ASSERT_PTR_NON_NULL(summitExp, false);
-
-    fprintf(stream, "%s %s %s %s %s\n",
-        summitExp->exp_id,
-        summitExp->camera,
-        summitExp->telescope,
-        summitExp->exp_type,
-        summitExp->uri
-    );
-
-    return true;
 }
 
