Index: /trunk/ippTools/src/dettool.c
===================================================================
--- /trunk/ippTools/src/dettool.c	(revision 9116)
+++ /trunk/ippTools/src/dettool.c	(revision 9117)
@@ -798,4 +798,55 @@
     PS_ASSERT_PTR_NON_NULL(config, false);
 
+    psString query = psStringCopy(
+            "SELECT detInputExp.det_id, detRun.det_type, rawImfile.*"
+            " FROM rawImfile"
+            " JOIN detInputExp USING(exp_tag) "
+            " JOIN detRun ON detInputExp.det_id = detRun.position"
+        );
+
+    if (config->where) {
+        psString whereClause = psDBGenerateWhereSQL(config->where, "rawImfile");
+        psStringAppend(&query, " %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");
+        psFree(query);
+    }
+    if (!psArrayLength(output)) {
+        // XXX check psError here
+        psError(PS_ERR_UNKNOWN, false, "no rawImfile 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, "rawImfile", !simple)) {
+        psError(PS_ERR_UNKNOWN, false, "failed to print array");
+        psFree(output);
+        return false;
+    }
+
+    psFree(output);
+
     return true;
 }
@@ -846,7 +897,12 @@
     psArray *output = p_psDBFetchResult(config->dbh);
     if (!output) {
+        psError(PS_ERR_UNKNOWN, false, "database error");
+        psFree(query);
+    }
+    if (!psArrayLength(output)) {
         // XXX check psError here
-        psError(PS_ERR_UNKNOWN, false, "no pending rawDetrendExp rows found");
-        return false;
+        psError(PS_ERR_UNKNOWN, false, "no rawImfile rows found");
+        psFree(output);
+        return true;
     }
 
@@ -862,5 +918,5 @@
 
     // negative simple so the default is true
-    if (!ippdbPrintMetadatas(stdout, output, "rawDetrendImfile", !simple)) {
+    if (!ippdbPrintMetadatas(stdout, output, "rawImfile", !simple)) {
         psError(PS_ERR_UNKNOWN, false, "failed to print array");
         psFree(output);
