Index: branches/jhoblitt/ippdb/src/ippdb.c
===================================================================
--- branches/jhoblitt/ippdb/src/ippdb.c	(revision 7460)
+++ branches/jhoblitt/ippdb/src/ippdb.c	(revision 7500)
@@ -10529,5 +10529,5 @@
 static void detRunRowFree(detRunRow *object);
 
-detRunRow *detRunRowAlloc(const char *det_type)
+detRunRow *detRunRowAlloc(const char *det_type, psS32 iteration)
 {
     detRunRow       *object;
@@ -10537,4 +10537,5 @@
 
     object->det_type = psStringCopy(det_type);
+    object->iteration = iteration;
 
     return object;
@@ -10562,4 +10563,9 @@
         return false;
     }
+    if (!psMetadataAddS32(md, PS_LIST_TAIL, "iteration", 0, NULL, 0)) {
+        psError(PS_ERR_UNKNOWN, false, "failed to add item iteration");
+        psFree(md);
+        return false;
+    }
 
     status = psDBCreateTable(dbh, DETRUN_TABLE_NAME, md);
@@ -10575,5 +10581,5 @@
 }
 
-bool detRunInsert(psDB * dbh, const char *det_type)
+bool detRunInsert(psDB * dbh, const char *det_type, psS32 iteration)
 {
     psMetadata      *md;
@@ -10586,4 +10592,9 @@
         return false;
     }
+    if (!psMetadataAddS32(md, PS_LIST_TAIL, "iteration", 0, NULL, iteration)) {
+        psError(PS_ERR_UNKNOWN, false, "failed to add item iteration");
+        psFree(md);
+        return false;
+    }
 
     status = psDBInsertOneRow(dbh, DETRUN_TABLE_NAME, md);
@@ -10593,5 +10604,5 @@
 }
 
-bool detRunPop(psDB *dbh, char **det_type)
+bool detRunPop(psDB *dbh, char **det_type, psS32 *iteration)
 {
     psArray         *rowSet;
@@ -10643,4 +10654,10 @@
         return false;
     }
+    *iteration = psMetadataLookupS32(&status, row, "iteration");
+    if (!status) {
+        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item iteration");
+        psFree(row);
+        return false;
+    }
 
     psFree(row);
@@ -10651,5 +10668,5 @@
 bool detRunInsertObject(psDB *dbh, detRunRow *object)
 {
-    return detRunInsert(dbh, object->det_type);
+    return detRunInsert(dbh, object->det_type, object->iteration);
 }
 
@@ -10657,11 +10674,12 @@
 {
     char            det_type[256];
-
-    if (!detRunPop(dbh, (char **)&det_type)) {
+    psS32           iteration;
+
+    if (!detRunPop(dbh, (char **)&det_type, &iteration)) {
         psError(PS_ERR_UNKNOWN, false, "failed to pop a database row");
         return NULL;
     }
 
-    return detRunRowAlloc(det_type);
+    return detRunRowAlloc(det_type, iteration);
 }
 
@@ -10767,4 +10785,9 @@
         return NULL;
     }
+    if (!psMetadataAddS32(md, PS_LIST_TAIL, "iteration", 0, NULL, object->iteration)) {
+        psError(PS_ERR_UNKNOWN, false, "failed to add item iteration");
+        psFree(md);
+        return NULL;
+    }
 
     return md;
@@ -10775,4 +10798,5 @@
     bool            status;
     char            *det_type;
+    psS32           iteration;
 
     det_type = psMetadataLookupPtr(&status, md, "det_type");
@@ -10781,6 +10805,11 @@
         return false;
     }
-
-    return detRunRowAlloc(det_type);
+    iteration = psMetadataLookupS32(&status, md, "iteration");
+    if (!status) {
+        psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item iteration");
+        return false;
+    }
+
+    return detRunRowAlloc(det_type, iteration);
 }
 psArray *detRunSelectRowObjects(psDB *dbh, const psMetadata *where, unsigned long long limit)
