Index: /trunk/ippTools/configure.ac
===================================================================
--- /trunk/ippTools/configure.ac	(revision 9424)
+++ /trunk/ippTools/configure.ac	(revision 9425)
@@ -16,5 +16,5 @@
 PKG_CHECK_MODULES([PSLIB], [pslib >= 0.12.99]) 
 PKG_CHECK_MODULES([PSMODULES], [psmodules >= 0.12.0]) 
-PKG_CHECK_MODULES([IPPDB], [ippdb >= 0.0.48]) 
+PKG_CHECK_MODULES([IPPDB], [ippdb >= 0.0.49]) 
 
 AC_PROG_PERL_MODULES(
Index: /trunk/ippTools/src/dettool.c
===================================================================
--- /trunk/ippTools/src/dettool.c	(revision 9424)
+++ /trunk/ippTools/src/dettool.c	(revision 9425)
@@ -65,5 +65,5 @@
 static bool rerunMode(pxConfig *config);
 
-static bool mapPositionToDetRun(psArray *mds);
+static bool convertDetIdToStr(psArray *mds);
 static detNormalizedStatImfileRow *detStackedToDetNormalizedStatImfile(pxConfig *config, detStackedImfileRow *stackedImfile);
 static  detNormalizedImfileRow *detNormalizedStatToDetNormalizedmfile(pxConfig *config, detNormalizedStatImfileRow *statImfile);
@@ -281,8 +281,8 @@
     }
 
-    // grab the 'position' column's value as the new det_id
     // the first iteration is always 0
     // XXX the camera name is set from the first inputExp
-    detRunInsert(config->dbh, 0, det_type, "run");
+    // XXX det_id
+    detRunInsert(config->dbh, 0, 0, det_type, "run");
     long det_id = psDBLastInsertID(config->dbh);
 
@@ -333,6 +333,5 @@
     {
         psMetadata *where = psMetadataAlloc();
-        // map det_id -> position
-        psMetadataAddS32(where, PS_LIST_TAIL, "position", 0, "==", det_id);
+        psMetadataAddS32(where, PS_LIST_TAIL, "det_id", 0, "==", det_id);
         detRuns = psDBSelectRows(config->dbh, "detRun", where, 0);
         psFree(where);
@@ -348,7 +347,7 @@
     }
 
-    // map position -> det_id
-    if (!mapPositionToDetRun(detRuns)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to map position -> det_id");
+    // convert det_id to a str externally
+    if (!convertDetIdToStr(detRuns)) {
+        psError(PS_ERR_UNKNOWN, false, "failed to convert det_id to a string");
         psFree(detRuns);
         return false;
@@ -366,17 +365,24 @@
 }
 
-static bool mapPositionToDetRun(psArray *mds)
+// This function is used to convert the det_id from an int, as it is used
+// internally, to be a string for external use.  The rational being that we may
+// want to change how det_id is generated in the future and don't want to
+// external programs to become depending on this value being an int.
+static bool convertDetIdToStr(psArray *mds)
 {
     PS_ASSERT_PTR_NON_NULL(mds, false);
 
     for (long i = 0; i < psArrayLength(mds); i++) {
+        psMetadata *md = mds->data[i];
         bool status = false;
-        psS32 position = psMetadataLookupS32(&status, mds->data[i], "position");
+        psS32 det_id = psMetadataLookupS32(&status, md, "det_id");
         if (!status) {
-            psError(PS_ERR_UNKNOWN, false, "failed to lookup value for position");
-            psFree(mds);
-            return false;
-        }
-        psMetadataAddS32(mds->data[i], PS_LIST_HEAD, "det_id", 0, NULL, position);
+            psError(PS_ERR_UNKNOWN, false, "failed to lookup value for det_id");
+            return false;
+        }
+        psMetadataRemove(md, 0, "det_id");
+        psString det_idStr = psDBIntToString((psU64)det_id);
+        psMetadataAddStr(mds->data[i], PS_LIST_HEAD, "det_id", 0, NULL, det_idStr);
+        psFree(det_idStr);
     }
 
@@ -486,8 +492,7 @@
     }
 
-    // grab the 'position' column's value as the new det_id
     // the first iteration is always 0
-    // XXX the camera name is set from the first inputExp
-    detRunInsert(config->dbh, 0, det_type, "run");
+    // XXX det_id
+    detRunInsert(config->dbh, 0, 0, det_type, "run");
     long det_id = psDBLastInsertID(config->dbh);
 
@@ -538,6 +543,5 @@
     {
         psMetadata *where = psMetadataAlloc();
-        // map det_id -> position
-        psMetadataAddS32(where, PS_LIST_TAIL, "position", 0, "==", det_id);
+        psMetadataAddS32(where, PS_LIST_TAIL, "det_id", 0, "==", det_id);
         detRuns = psDBSelectRows(config->dbh, "detRun", where, 0);
         psFree(where);
@@ -553,7 +557,7 @@
     }
 
-    // map position -> det_id
-    if (!mapPositionToDetRun(detRuns)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to map position -> det_id");
+    // convert det_id to a string externaly
+    if (!convertDetIdToStr(detRuns)) {
+        psError(PS_ERR_UNKNOWN, false, "failed to convert det_id to a string");
         psFree(detRuns);
         return false;
@@ -583,7 +587,7 @@
     }
 
-    // map position -> det_id
-    if (!mapPositionToDetRun(runs)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to map position -> det_id");
+    // convert det_id to a string externaly
+    if (!convertDetIdToStr(runs)) {
+        psError(PS_ERR_UNKNOWN, false, "failed to convert det_id to a string");
         psFree(runs);
         return false;
@@ -695,5 +699,5 @@
             " FROM rawImfile"
             " JOIN detInputExp USING(exp_tag) "
-            " JOIN detRun ON detInputExp.det_id = detRun.position"
+            " JOIN detRun ON detInputExp.det_id = detRun.det_id"
             " WHERE detRun.state = 'run'"
         );
@@ -752,5 +756,5 @@
     // select det_id, det_type & rawImfile *
     // get det_id from detInputExp.det_id
-    // get det_type from detRun.position
+    // get det_type from detRun.det_id
     //
     // det_id is in detInputExp
@@ -763,5 +767,5 @@
             " FROM rawImfile"
             " LEFT JOIN detInputExp USING(exp_tag) "
-            " LEFT JOIN detRun ON detInputExp.det_id = detRun.position"
+            " LEFT JOIN detRun ON detInputExp.det_id = detRun.det_id"
             " LEFT JOIN detProcessedImfile"
                 " ON detInputExp.det_id = detProcessedImfile.det_id"
@@ -1033,5 +1037,5 @@
         " FROM detRun"
         " JOIN detInputExp"
-        "    ON detRun.position = detInputExp.det_id"
+        "    ON detRun.det_id = detInputExp.det_id"
         "    AND detRun.iteration = detInputExp.iteration"
         " JOIN rawDetrendExp"
@@ -1055,5 +1059,5 @@
         "    rawImfile.class_id,"
         "    detInputExp.exp_tag,"
-        "    detRun.position"
+        "    detRun.det_id"
         " HAVING"
         "    COUNT(detProcessedImfile.class_id) = COUNT(rawImfile.class_id)"
@@ -1191,5 +1195,5 @@
         " FROM detRun"
         " JOIN detInputExp"
-        "    ON detRun.position = detInputExp.det_id"
+        "    ON detRun.det_id = detInputExp.det_id"
         "    AND detRun.iteration = detInputExp.iteration"
         " JOIN rawDetrendExp"
@@ -1209,10 +1213,10 @@
         "   AND detProcessedExp.exp_tag IS NULL"
         "   AND detInputExp.include = 1"
-        "   AND detRun.position = %s"
+        "   AND detRun.det_id = %s"
         "   AND detProcessedImfile.exp_tag = '%s'"
         " GROUP BY"
         "    detProcessedImfile.class_id,"
         "    rawImfile.class_id,"
-        "    detRun.position"
+        "    detRun.det_id"
         " HAVING"
         "    COUNT(detProcessedImfile.class_id) = COUNT(rawImfile.class_id)"
@@ -1342,5 +1346,5 @@
         " FROM detRun"
         " JOIN detInputExp"
-        "    ON detRun.position = detInputExp.det_id"
+        "    ON detRun.det_id = detInputExp.det_id"
         "    AND detRun.iteration = detInputExp.iteration"
         " JOIN rawDetrendExp"
@@ -1364,5 +1368,5 @@
         " GROUP BY"
         "    rawImfile.class_id,"
-        "    detRun.position"
+        "    detRun.det_id"
         " HAVING"
         "    COUNT(detProcessedImfile.class_id) = COUNT(rawImfile.class_id)"
@@ -1429,7 +1433,7 @@
         " FROM detProcessedImfile"
         " JOIN detRun"
-        "   ON detRun.position = detProcessedImfile.det_id"
+        "   ON detRun.det_id = detProcessedImfile.det_id"
         " JOIN detInputExp"
-        "   ON detRun.position = detInputExp.det_id"
+        "   ON detRun.det_id = detInputExp.det_id"
         "   AND detRun.iteration = detInputExp.iteration"
         " WHERE"
@@ -1702,5 +1706,5 @@
     PS_ASSERT_PTR_NON_NULL(config, false);
 
-    // select detRun.position (det_id)
+    // select detRun.det_id (det_id)
     // select detRun.iteration
     // by:
@@ -1717,5 +1721,5 @@
     psString query = psStringCopy(
         "SELECT DISTINCT"
-        "     detRun.position AS det_id,"
+        "     detRun.det_id AS det_id,"
         "     detRun.det_type,"
         "     detRun.iteration,"
@@ -1723,5 +1727,5 @@
         " FROM detRun"
         " JOIN detInputExp"
-        "     ON detRun.position = detInputExp.det_id"
+        "     ON detRun.det_id = detInputExp.det_id"
         "     AND detRun.iteration = detInputExp.iteration"
         " JOIN rawDetrendExp"
@@ -1731,5 +1735,5 @@
         "     AND detInputExp.iteration = detStackedImfile.iteration"
         " LEFT JOIN detNormalizedStatImfile"
-        "     ON detRun.position = detNormalizedStatImfile.det_id"
+        "     ON detRun.det_id = detNormalizedStatImfile.det_id"
         "     AND detRun.iteration = detNormalizedStatImfile.iteration"
         " WHERE"
@@ -1740,5 +1744,5 @@
         "     rawDetrendExp.exp_tag,"
         "     detRun.iteration,"
-        "     detRun.position"
+        "     detRun.det_id"
         " HAVING MAX(rawDetrendExp.imfiles) = COUNT(detStackedImfile.class_id)"
         );
@@ -1922,16 +1926,16 @@
         " FROM detRun"
         " JOIN detInputExp"
-        "   ON detRun.position = detInputExp.det_id"
+        "   ON detRun.det_id = detInputExp.det_id"
         "   AND detRun.iteration = detInputExp.iteration"
         " JOIN detStackedImfile"
-        "   ON detRun.position = detStackedImfile.det_id"
+        "   ON detRun.det_id = detStackedImfile.det_id"
         "   AND detRun.iteration = detStackedImfile.iteration"
         " JOIN detNormalizedStatImfile"
-        "   ON detRun.position = detNormalizedStatImfile.det_id"
+        "   ON detRun.det_id = detNormalizedStatImfile.det_id"
         "   AND detRun.iteration = detNormalizedStatImfile.iteration"
         " JOIN rawDetrendExp"
         "   ON detInputExp.exp_tag = rawDetrendExp.exp_tag"
         " LEFT JOIN detNormalizedImfile"
-        "   ON detRun.position = detNormalizedImfile.det_id"
+        "   ON detRun.det_id = detNormalizedImfile.det_id"
         "   AND detRun.iteration = detNormalizedImfile.iteration"
         "   AND detNormalizedStatImfile.class_id = detNormalizedImfile.class_id"
@@ -2231,5 +2235,5 @@
     psString query = psStringCopy(
         " SELECT DISTINCT"
-        "    detRun.position as det_id,"
+        "    detRun.det_id as det_id,"
         "    detRun.iteration,"
         "    detRun.det_type,"
@@ -2240,5 +2244,5 @@
         " FROM detRun"
         " JOIN detInputExp"
-        "    ON detRun.position = detInputExp.det_id"
+        "    ON detRun.det_id = detInputExp.det_id"
         "    AND detRun.iteration = detInputExp.iteration"
         " JOIN rawDetrendExp"
@@ -2260,5 +2264,5 @@
         " GROUP BY"
         "    detNormalizedImfile.iteration,"
-        "    detRun.position"
+        "    detRun.det_id"
         " HAVING"
         "    COUNT(detNormalizedImfile.class_id) = COUNT(rawImfile.class_id)"
@@ -2386,5 +2390,5 @@
     psString query = psStringCopy(
         " SELECT DISTINCT"
-        "    detRun.position as det_id,"
+        "    detRun.det_id as det_id,"
         "    detRun.iteration,"
         "    detRun.det_type,"
@@ -2395,5 +2399,5 @@
         " FROM detRun"
         " JOIN detInputExp"
-        "    ON detRun.position = detInputExp.det_id"
+        "    ON detRun.det_id = detInputExp.det_id"
         "    AND detRun.iteration = detInputExp.iteration"
         " JOIN rawDetrendExp"
@@ -2413,9 +2417,9 @@
         "   AND detNormalizedExp.iteration IS NULL"
         "   AND detInputExp.include = 1"
-        "   AND detRun.position = %s"
+        "   AND detRun.det_id = %s"
         "   AND detNormalizedImfile.iteration = %d"
         " GROUP BY"
         "    detNormalizedImfile.iteration,"
-        "    detRun.position"
+        "    detRun.det_id"
         " HAVING"
         "    COUNT(detNormalizedImfile.class_id) = COUNT(rawImfile.class_id)"
@@ -2606,17 +2610,17 @@
         " FROM detRun"
         " JOIN detInputExp"
-        "   ON detRun.position = detInputExp.det_id"
+        "   ON detRun.det_id = detInputExp.det_id"
         "   AND detRun.iteration = detInputExp.iteration"
         " JOIN rawDetrendExp"
         "   ON detInputExp.exp_tag = rawDetrendExp.exp_tag"
         " JOIN detProcessedImfile"
-        "   ON detRun.position = detProcessedImfile.det_id"
+        "   ON detRun.det_id = detProcessedImfile.det_id"
         "   AND detInputExp.exp_tag = detProcessedImfile.exp_tag"
         " JOIN detNormalizedImfile"
-        "   ON detRun.position = detNormalizedImfile.det_id"
+        "   ON detRun.det_id = detNormalizedImfile.det_id"
         "   AND detRun.iteration = detNormalizedImfile.iteration"
         "   AND detProcessedImfile.class_id = detNormalizedImfile.class_id"
         " LEFT JOIN detResidImfile"
-        "   ON detRun.position = detResidImfile.det_id"
+        "   ON detRun.det_id = detResidImfile.det_id"
         "   AND detRun.iteration = detResidImfile.iteration"
         "   AND detProcessedImfile.exp_tag = detResidImfile.exp_tag"
@@ -2689,5 +2693,5 @@
         " FROM detNormalizedImfile"
         " JOIN detRun"
-        "   ON detNormalizedImfile.det_id = detRun.position"
+        "   ON detNormalizedImfile.det_id = detRun.det_id"
         " WHERE"
         "   detRun.state = 'run'"
@@ -3082,5 +3086,5 @@
 
 
-    // select detRun.position
+    // select detRun.det_id
     // select detRun.iteration
     // select detRun.det_type
@@ -3103,5 +3107,5 @@
         " FROM"
         "   (SELECT DISTINCT"
-        "       detRun.position AS det_id,"
+        "       detRun.det_id AS det_id,"
         "       detRun.iteration,"
         "       detRun.det_type,"
@@ -3111,14 +3115,14 @@
         "   FROM detRun"
         "       LEFT JOIN detInputExp"
-        "       ON detRun.position = detInputExp.det_id"
+        "       ON detRun.det_id = detInputExp.det_id"
         "       AND detRun.iteration = detInputExp.iteration"
         "   LEFT JOIN rawDetrendExp"
         "       ON detInputExp.exp_tag = rawDetrendExp.exp_tag"
         "   LEFT JOIN detResidImfile"
-        "       ON detRun.position = detResidImfile.det_id"
+        "       ON detRun.det_id = detResidImfile.det_id"
         "       AND detRun.iteration = detResidImfile.iteration"
         "       AND detInputExp.exp_tag = detResidImfile.exp_tag"
         "   LEFT JOIN detResidExp"
-        "       ON detRun.position = detResidExp.det_id"
+        "       ON detRun.det_id = detResidExp.det_id"
         "       AND detRun.iteration = detResidExp.iteration"
         "       AND detInputExp.exp_tag = detResidExp.exp_tag"
@@ -3131,5 +3135,5 @@
         "       detInputExp.exp_tag,"
         "       detRun.iteration,"
-        "       detRun.position"
+        "       detRun.det_id"
         "   HAVING"
         "       rawDetrendExp.imfiles = COUNT(detResidImfile.class_id)"
@@ -3199,5 +3203,5 @@
 
 
-    // select detRun.position
+    // select detRun.det_id
     // select detRun.iteration
     // select detRun.det_type
@@ -3219,5 +3223,5 @@
         " FROM"
         "   (SELECT DISTINCT"
-        "       detRun.position AS det_id,"
+        "       detRun.det_id AS det_id,"
         "       detRun.iteration,"
         "       detRun.det_type,"
@@ -3227,14 +3231,14 @@
         "   FROM detRun"
         "       LEFT JOIN detInputExp"
-        "       ON detRun.position = detInputExp.det_id"
+        "       ON detRun.det_id = detInputExp.det_id"
         "       AND detRun.iteration = detInputExp.iteration"
         "   LEFT JOIN rawDetrendExp"
         "       ON detInputExp.exp_tag = rawDetrendExp.exp_tag"
         "   LEFT JOIN detResidImfile"
-        "       ON detRun.position = detResidImfile.det_id"
+        "       ON detRun.det_id = detResidImfile.det_id"
         "       AND detRun.iteration = detResidImfile.iteration"
         "       AND detInputExp.exp_tag = detResidImfile.exp_tag"
         "   LEFT JOIN detResidExp"
-        "       ON detRun.position = detResidExp.det_id"
+        "       ON detRun.det_id = detResidExp.det_id"
         "       AND detRun.iteration = detResidExp.iteration"
         "       AND detInputExp.exp_tag = detResidExp.exp_tag"
@@ -3247,5 +3251,5 @@
         "       detInputExp.exp_tag,"
         "       detRun.iteration,"
-        "       detRun.position"
+        "       detRun.det_id"
         "   HAVING"
         "       rawDetrendExp.imfiles = COUNT(detResidImfile.class_id)"
@@ -3491,5 +3495,5 @@
             "   USING(det_id, exp_tag, iteration)"
             " JOIN detRun"
-            "   ON detResidExp.det_id = detRun.position"
+            "   ON detResidExp.det_id = detRun.det_id"
             "   AND detResidExp.iteration = detRun.iteration"
             " WHERE"
@@ -3552,5 +3556,5 @@
      */
 
-    // select detRun.position
+    // select detRun.det_id
     // select detRun.iteration
     // select detRun.det_type
@@ -3569,5 +3573,5 @@
         " FROM"
         "   (SELECT DISTINCT"
-        "       detRun.position AS det_id,"
+        "       detRun.det_id AS det_id,"
         "       detRun.iteration,"
         "       detRun.det_type,"
@@ -3576,10 +3580,10 @@
         "   FROM detRun"
         "       LEFT JOIN detInputExp"
-        "       ON detRun.position = detInputExp.det_id"
+        "       ON detRun.det_id = detInputExp.det_id"
         "       AND detRun.iteration = detInputExp.iteration"
         "   LEFT JOIN rawDetrendExp"
         "       ON detInputExp.exp_tag = rawDetrendExp.exp_tag"
         "   LEFT JOIN detResidExp"
-        "       ON detRun.position = detResidExp.det_id"
+        "       ON detRun.det_id = detResidExp.det_id"
         "       AND detRun.iteration = detResidExp.iteration"
         "       AND detInputExp.exp_tag = detResidExp.exp_tag"
@@ -3587,5 +3591,5 @@
         "       detRun.state = 'run'"
         "   GROUP BY"
-        "       detRun.position,"
+        "       detRun.det_id,"
         "       detRun.iteration"
         "   HAVING"
@@ -3820,5 +3824,5 @@
     PS_ASSERT_PTR_NON_NULL(config, false);
 
-    // select detRun.position
+    // select detRun.det_id
     // select detRun.iteration
     // by:
@@ -3834,15 +3838,15 @@
         " FROM"
         "   (SELECT DISTINCT"
-        "       detRun.position AS det_id,"
+        "       detRun.det_id AS det_id,"
         "       detRun.iteration,"
         "       detInputExp.exp_tag"
         "   FROM detRun"
         "       LEFT JOIN detInputExp"
-        "       ON detRun.position = detInputExp.det_id"
+        "       ON detRun.det_id = detInputExp.det_id"
         "       AND detRun.iteration = detInputExp.iteration"
         "   LEFT JOIN rawDetrendExp"
         "       ON detInputExp.exp_tag = rawDetrendExp.exp_tag"
         "   LEFT JOIN detResidExp"
-        "       ON detRun.position = detResidExp.det_id"
+        "       ON detRun.det_id = detResidExp.det_id"
         "       AND detRun.iteration = detResidExp.iteration"
         "       AND detInputExp.exp_tag = detResidExp.exp_tag"
@@ -3850,5 +3854,5 @@
         "       detRun.state = 'run'"
         "   GROUP BY"
-        "       detRun.position,"
+        "       detRun.det_id,"
         "       detRun.iteration"
         "   HAVING"
@@ -4067,5 +4071,5 @@
     // -again
 
-    // select detRun.position
+    // select detRun.det_id
     // select detRun.iteration
     // select detInputExp.exp_tag
@@ -4079,5 +4083,5 @@
     psString query = psStringCopy(
         "SELECT DISTINCT"
-        "   detRun.position AS det_id,"
+        "   detRun.det_id AS det_id,"
         "   detRun.iteration,"
         "   detInputExp.exp_tag,"
@@ -4085,8 +4089,8 @@
         " FROM detRun"
         " JOIN detInputExp"
-        "   ON detRun.position = detInputExp.det_id"
+        "   ON detRun.det_id = detInputExp.det_id"
         "   AND detRun.iteration = detInputExp.iteration"
         " JOIN detResidExp"
-        "   ON detRun.position = detResidExp.det_id"
+        "   ON detRun.det_id = detResidExp.det_id"
         "   AND detRun.iteration = detResidExp.iteration"
         "   AND detInputExp.exp_tag = detResidExp.exp_tag"
@@ -4099,10 +4103,10 @@
     psStringAppend (
 	&query,
-	"  AND detRun.position = '%s'", det_id);
+	"  AND detRun.det_id = '%s'", det_id);
 
     psStringAppend (
 	&query, 
 	" GROUP BY"
-        "   detRun.position,"
+        "   detRun.det_id,"
         "   detRun.iteration,"
         "   detInputExp.exp_tag"
@@ -4374,5 +4378,5 @@
     PS_ASSERT_PTR_NON_NULL(det_id, 0);
 
-    char *query = "UPDATE detRun SET iteration = iteration + 1 WHERE position = '%s'";
+    char *query = "UPDATE detRun SET iteration = iteration + 1 WHERE det_id = '%s'";
     if (!p_psDBRunQuery(config->dbh, query, det_id)) {
         psError(PS_ERR_UNKNOWN, false,
@@ -4382,5 +4386,5 @@
 
     psMetadata *where = psMetadataAlloc();
-    if (!psMetadataAddS32(where, PS_LIST_TAIL, "position", 0, "==",
+    if (!psMetadataAddS32(where, PS_LIST_TAIL, "det_id", 0, "==",
                 (psS32)atol(det_id))) {
         psError(PS_ERR_UNKNOWN, false, "failed to add item det_id");
@@ -4414,5 +4418,5 @@
     PS_ASSERT_PTR_NON_NULL(state, false);
 
-    char *query = "UPDATE detRun SET state = '%s' WHERE position = '%s'";
+    char *query = "UPDATE detRun SET state = '%s' WHERE det_id = '%s'";
     if (!p_psDBRunQuery(config->dbh, query, state, det_id)) {
         psError(PS_ERR_UNKNOWN, false,
