Index: /trunk/ippTools/src/dettool.c
===================================================================
--- /trunk/ippTools/src/dettool.c	(revision 11146)
+++ /trunk/ippTools/src/dettool.c	(revision 11147)
@@ -981,5 +981,5 @@
         return false;
     }
-    
+
     // lookup the detRun that we will be basing this one on
     psArray *detRuns = NULL;
@@ -999,8 +999,8 @@
         return false;                   // unreachable
     }
-   
+
     // pull the detRun object out the result array
     detRunRow *detRun = psMemIncrRefCounter(detRuns->data[0]);
- 
+
     // discard the resultarray
     psFree(detRuns)
@@ -1008,8 +1008,8 @@
     // set the det_id to 0/NULL so the database can assign it
     detRun->det_id = 0;
-    
+
     // reset the iteration to 0
     detRun->iteration = 0;
-    
+
     // reset the state to "run"
     psFree(detRun->state);
@@ -1219,5 +1219,5 @@
     psFree(detRun);
 
-    // get the det_id 
+    // get the det_id
     long newDet_id = psDBLastInsertID(config->dbh);
 
@@ -2327,11 +2327,4 @@
     }
 
-    if (!p_psDBRunQuery(config->dbh, query)) {
-        psError(PS_ERR_UNKNOWN, false, "database error");
-        psFree(query);
-        return false;
-    }
-    psFree(query);
-
     if (faulted) {
         // list only faulted rows
@@ -2341,4 +2334,11 @@
         psStringAppend(&query, " %s", "AND detProcessedImfile.fault = 0");
     }
+
+    if (!p_psDBRunQuery(config->dbh, query)) {
+        psError(PS_ERR_UNKNOWN, false, "database error");
+        psFree(query);
+        return false;
+    }
+    psFree(query);
 
     // treat limit == 0 as "no limit"
@@ -3255,5 +3255,5 @@
     }
 #endif
-    
+
     // treat limit == 0 as "no limit"
     if (limit) {
@@ -6068,7 +6068,7 @@
     // check that state is a valid string value
     if (!(
-            (strncmp(state, "run", 4) == 0) 
-            || (strncmp(state, "stop", 5) == 0) 
-            || (strncmp(state, "reg", 4) == 0) 
+            (strncmp(state, "run", 4) == 0)
+            || (strncmp(state, "stop", 5) == 0)
+            || (strncmp(state, "reg", 4) == 0)
         )
     ) {
@@ -6095,6 +6095,6 @@
     // check that state is a valid string value
     if (!(
-            (strncmp(mode, "master", 7) == 0) 
-            || (strncmp(mode, "verify", 7) == 0) 
+            (strncmp(mode, "master", 7) == 0)
+            || (strncmp(mode, "verify", 7) == 0)
         )
     ) {
