Index: /trunk/ippTools/src/dettool.c
===================================================================
--- /trunk/ippTools/src/dettool.c	(revision 7350)
+++ /trunk/ippTools/src/dettool.c	(revision 7351)
@@ -1390,4 +1390,6 @@
     // check det_id, exp_id, & class_id against the input rawImfiles
     
+    // XXX what we really want here is to do a join but psDB doesn't support
+    // that type of operation 
     // we have to generate our own where claus as we want to exclude -stats
     // from the search
@@ -1404,9 +1406,4 @@
         return false;
     }
-    if (!psMetadataAddStr(where, PS_LIST_TAIL, "class_id", 0, "==", class_id)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to add item class_id");
-        psFree(where);
-        return false;
-    }
 
     psArray *rawImfiles = searchRawImfiles(config, where);
@@ -1419,7 +1416,33 @@
     }
 
-    // database sanity check
-    if (psArrayLength(rawImfiles) > 1) {
-        // abort
+    // iterate through rawImfiles looking for a match to our class_id
+    bool found = false;
+    for (long i = 0; i < psArrayLength(rawImfiles); i++) {
+        if (strcmp(class_id,
+                ((rawImfileRow *)rawImfiles->data[i])->class_id) == 0) {
+            found = true; 
+            break;
+        }
+    }
+
+    if (!found) {
+        psError(PS_ERR_UNKNOWN, true,
+    "det_id %s, exp_id %s, class_id %s does not corespond to an input imfile",
+            det_id, exp_id, class_id);
+        return false;
+    }
+
+    // create a new detResidImfileRow and insert it
+    detResidImfileAnalysisRow *residImfile = detResidImfileAnalysisRowAlloc(
+                (psS32)atol(det_id),
+                exp_id,
+                class_id,
+                stats,
+                recipe
+            );
+
+    if (!detResidImfileAnalysisInsertObject(config->dbh, residImfile)) {
+            psError(PS_ERR_UNKNOWN, false, "database error");
+            return false;
     }
 
