Index: /trunk/ippTools/src/dettool.c
===================================================================
--- /trunk/ippTools/src/dettool.c	(revision 8288)
+++ /trunk/ippTools/src/dettool.c	(revision 8289)
@@ -213,5 +213,5 @@
     }
 
-    if (where->list->n < 1) {
+    if (psListLength(where->list) < 1) {
         psFree(where);
         where = NULL;
@@ -226,5 +226,5 @@
     }
 
-    // we should have one rawDetrendExp row be exp_id specified
+    // we should have one rawDetrendExp row per exp_id specified
     if (psListLength(item->data.list) != psArrayLength(detrendExps)) {
         psAbort(config->argv[0],
@@ -260,14 +260,13 @@
     psFree(detrendExps);
 
-    for (long i = 0; i < psArrayLength(inputExps); i++) {
-        if (!detInputExpInsertObject(config->dbh, inputExps->data[i])) {
+    // insert detInputExp objects into the database
+    if (!detInputExpInsertObjects(config->dbh, inputExps)) {
+        psError(PS_ERR_UNKNOWN, false, "database error");
+        // rollback
+        if (!psDBRollback(config->dbh)) {
             psError(PS_ERR_UNKNOWN, false, "database error");
-            // rollback
-            if (!psDBRollback(config->dbh)) {
-                psError(PS_ERR_UNKNOWN, false, "database error");
-            }
-            psFree(inputExps);
-            return false;
-        }
+        }
+        psFree(inputExps);
+        return false;
     }
     psFree(inputExps);
@@ -279,6 +278,54 @@
     }
 
+    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;
+        }
+    }
+
     // print the new det_id
-    printf("%ld\n", det_id);
+    psArray *detRuns = NULL;
+    {
+        psMetadata *where = psMetadataAlloc();
+        // map det_id -> position
+        psMetadataAddS32(where, PS_LIST_TAIL, "position", 0, "==", det_id);
+        detRuns = psDBSelectRows(config->dbh, "detRun", where, 0);
+        psFree(where);
+    }
+    if (!detRuns) {
+        psError(PS_ERR_UNKNOWN, false, "can't find the detRun we just created");
+        return false;
+    }
+    // sanity check results
+    if (psArrayLength(detRuns) != 1) {
+        psAbort(config->argv[0], "found more then one detRun matching det_id %ld(this should not happen)", det_id);
+        return false;
+    }
+
+    // map position -> det_id
+    // but leave position in the metadata as ippdbPrintMetadatas() will strip it
+    // for us
+    for (long i = 0; i < psArrayLength(detRuns); i++) {
+        bool status = false;
+        psS32 position = psMetadataLookupS32(&status, detRuns->data[i], "position");
+        if (!status) {
+            psError(PS_ERR_UNKNOWN, false, "failed to lookup value for position");
+            psFree(detRuns);
+            return false;
+        }
+        psMetadataAddS32(detRuns->data[i], PS_LIST_HEAD, "det_id", 0, NULL, position);
+    }
+
+    // negative simple so the default is true
+    if (!ippdbPrintMetadatas(stdout, detRuns, "detRun", !simple)) {
+        psError(PS_ERR_UNKNOWN, false, "failed to print array");
+        psFree(detRuns);
+        return false;
+    }
+    psFree(detRuns);
 
     return true;
Index: /trunk/ippTools/src/dettoolConfig.c
===================================================================
--- /trunk/ippTools/src/dettoolConfig.c	(revision 8288)
+++ /trunk/ippTools/src/dettoolConfig.c	(revision 8289)
@@ -45,4 +45,6 @@
     psMetadataAddStr(definebyexpArgs, PS_LIST_TAIL, "-det_type",  0,
             "define the type of detrend run (required)", NULL);
+    psMetadataAddBool(definebyexpArgs, PS_LIST_TAIL, "-simple",  0,
+            "use the simple output format", false);
 
     // -runs
