Index: /trunk/ippTools/src/dettool.c
===================================================================
--- /trunk/ippTools/src/dettool.c	(revision 8377)
+++ /trunk/ippTools/src/dettool.c	(revision 8378)
@@ -42,4 +42,5 @@
 static bool mapPositionToDetRun(psArray *mds);
 static detNormalizedStatImfileRow *detStackedToDetNormalizedStatImfile(pxConfig *config, detStackedImfileRow *stackedImfile);
+static  detNormalizedImfileRow *detNormalizedStatToDetNormalizedmfile(pxConfig *config, detNormalizedStatImfileRow *statImfile);
 static psArray *validDetInputClassIds(pxConfig *config, const char *det_id);
 static psArray *searchInputImfiles(pxConfig *config, const char *det_id);
@@ -2039,8 +2040,8 @@
     // where det_id, iteration, class_id is not in detNormalizedImfile
     psString query = psStringCopy(
-        "SELECT DISTINCT"
+        "SELECT"
         "   detNormalizedStatImfile.*"
         " FROM detNormalizedStatImfile"
-        " LEFT JOIN detNormalizedStatImfile"
+        " LEFT JOIN detNormalizedImfile"
         "   USING(det_id, iteration, class_id)"
         " WHERE"
@@ -2050,11 +2051,61 @@
         );
 
-# if 0
-    if (config->where) {
-        psString whereClaus = psDBGenerateWhereConditionSQL(config->where, "detStackedImfile");
-        psStringAppend(&query, " AND %s", whereClaus);
-        psFree(whereClaus);
-    }
-#endif
+    {
+        // build a query to search by det_id, iteration, class_id
+        psMetadata *where = psMetadataAlloc();
+        bool status = false;
+        psString det_id = psMetadataLookupStr(&status, config->args, "-det_id");
+        if (!status) {
+            psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -det_id");
+            psFree(where);
+            psFree(query);
+            return false;
+        }
+        if (det_id) {
+            if (!psMetadataAddStr(where, PS_LIST_TAIL, "det_id", 0, "==", det_id)) {
+                psError(PS_ERR_UNKNOWN, false, "failed to add item det_id");
+                psFree(where);
+                psFree(query);
+                return false;
+            }
+        }
+        psS32 iteration = psMetadataLookupS32(&status, config->args, "-iteration");
+        if (!status) {
+            psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -iteration");
+            psFree(where);
+            psFree(query);
+            return false;
+        }
+        // always set iteration
+        if (!psMetadataAddS32(where, PS_LIST_TAIL, "iteration", 0, "==", iteration)) {
+            psError(PS_ERR_UNKNOWN, false, "failed to add item iteration");
+            psFree(where);
+            psFree(query);
+            return false;
+        }
+        psString class_id = psMetadataLookupStr(&status, config->args, "-class_id");
+        if (!status) {
+            psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -class_id");
+            psFree(where);
+            psFree(query);
+            return false;
+        }
+        if (class_id) {
+            if (!psMetadataAddStr(where, PS_LIST_TAIL, "class_id", 0, "==", class_id)) {
+                psError(PS_ERR_UNKNOWN, false, "failed to add item class_id");
+                psFree(where);
+                psFree(query);
+                return false;
+            }
+        }
+
+        // there's not
+        psString whereClaus = psDBGenerateWhereConditionSQL(where, "detNormalizedStatImfile");
+        psFree(where);
+        if (whereClaus) {
+            psStringAppend(&query, " AND %s", whereClaus);
+            psFree(whereClaus);
+        }
+    }
 
     if (!p_psDBRunQuery(config->dbh, query)) {
@@ -2079,13 +2130,12 @@
     }
 
-#if 0
     for (long i = 0; i < psArrayLength(output); i++) {
         psMetadata *row = output->data[i];
-        // convert metadata into a detStackedImfile object
-        detStackedImfileRow *stackedImfile = detStackedImfileObjectFromMetadata(row);
-        // convert detStackedImfile object into a detNormalizedStat object
-        detNormalizedStatImfileRow *stat = detStackedToDetNormalizedStatImfile(config, stackedImfile);
-        psFree(stackedImfile);
-        if (!stat) {
+        // convert metadata into a detNormalizedStatImfile object
+        detNormalizedStatImfileRow *statImfile = detNormalizedStatImfileObjectFromMetadata(row);
+        // convert detNormalizedStatImfile object into a detNormalizedImfile
+        detNormalizedImfileRow *normalizedImfile  = detNormalizedStatToDetNormalizedmfile(config, statImfile);
+        psFree(statImfile);
+        if (!normalizedImfile) {
             if (!psDBRollback(config->dbh)) {
                 psError(PS_ERR_UNKNOWN, false, "database error");
@@ -2096,13 +2146,13 @@
         }
         // insert detNormlized Stat object into the database
-        if (!detNormalizedStatImfileInsertObject(config->dbh, stat)) {
+        if (!detNormalizedImfileInsertObject(config->dbh, normalizedImfile)) {
             if (!psDBRollback(config->dbh)) {
                 psError(PS_ERR_UNKNOWN, false, "database error");
             }
             psError(PS_ERR_UNKNOWN, false, "database error");
-            psFree(stat);
+            psFree(normalizedImfile);
             psFree(output);
         }
-        psFree(stat);
+        psFree(normalizedImfile);
     }
 
@@ -2115,7 +2165,28 @@
 
     return true;
-#endif
-
-    return true;
+}
+
+static  detNormalizedImfileRow *detNormalizedStatToDetNormalizedmfile(pxConfig *config, detNormalizedStatImfileRow *statImfile)
+{
+    PS_ASSERT_PTR_NON_NULL(config, NULL);
+    PS_ASSERT_PTR_NON_NULL(statImfile, NULL);
+
+    bool status = false;
+    psString uri = psMetadataLookupStr(&status, config->args, "-uri");
+    if (!status) {
+        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -uri");
+        return false;
+    }
+    if (!uri) {
+        psError(PS_ERR_UNKNOWN, true, "-uri is required");
+        return false;
+    }
+
+    return detNormalizedImfileRowAlloc(
+        statImfile->det_id,
+        statImfile->iteration,
+        statImfile->class_id,
+        uri
+    );
 }
 
Index: /trunk/ippTools/src/dettoolConfig.c
===================================================================
--- /trunk/ippTools/src/dettoolConfig.c	(revision 8377)
+++ /trunk/ippTools/src/dettoolConfig.c	(revision 8378)
@@ -231,6 +231,4 @@
     psMetadataAddStr(addnormalizedArgs, PS_LIST_TAIL, "-uri",  0,
         "define URI (required)", NULL);
-    psMetadataAddStr(addnormalizedArgs, PS_LIST_TAIL, "-recip",  0,
-        "define recipe (required)", NULL);
 
     // -normalized
