Index: trunk/ippTools/src/pxchip.c
===================================================================
--- trunk/ippTools/src/pxchip.c	(revision 20750)
+++ trunk/ippTools/src/pxchip.c	(revision 21308)
@@ -235,4 +235,10 @@
     PS_ASSERT_PTR_NON_NULL(config, false);
 
+    if (!psDBTransaction(config->dbh)) {
+        psError(PS_ERR_UNKNOWN, false, "database error");
+        return false;
+    }
+
+
     // create a chipRun
     if (!chipRunInsert(config->dbh,
@@ -249,9 +255,33 @@
             end_stage)
     ) {
+        if (!psDBRollback(config->dbh)) {
+            psError(PS_ERR_UNKNOWN, false, "database error failed to rollback transaction");
+        }
         psError(PS_ERR_UNKNOWN, false, "database error");
         return 0;
     }
 
-    return psDBLastInsertID(config->dbh);
-}
-
+    psS64 chip_id =  psDBLastInsertID(config->dbh);
+
+    // Create rows in chipImfile table for each input exposure. 
+    // This creates the chip_image_id values
+    psString query = "INSERT INTO chipImfile "
+                     "SELECT %" PRId64 ", class_id, 0 FROM rawImfile WHERE exp_id = %" PRId64;
+
+    if (!p_psDBRunQuery(config->dbh, query, chip_id, exp_id)) {
+        psError(PS_ERR_UNKNOWN, false, "database error");
+        // rollback
+        if (!psDBRollback(config->dbh)) {
+            psError(PS_ERR_UNKNOWN, false, "database error");
+        }
+        psError(PS_ERR_UNKNOWN, false, "database error");
+        return 0;
+    }
+    if (!psDBCommit(config->dbh)) {
+        psError(PS_ERR_UNKNOWN, false, "database error");
+        return 0;
+    }
+    
+    return chip_id;
+}
+
