Index: trunk/ippTools/src/flatcorr.c
===================================================================
--- trunk/ippTools/src/flatcorr.c	(revision 19370)
+++ trunk/ippTools/src/flatcorr.c	(revision 19371)
@@ -131,5 +131,5 @@
 
     if (where && psListLength(where->list)) {
-        psString whereClause = psDBGenerateWhereConditionSQL(where, "rawExp");
+        psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
         psStringAppend(&query, " AND %s", whereClause);
         psFree(whereClause);
@@ -177,5 +177,6 @@
 
     // create a new flatcorrRun
-    if (!flatcorrRunInsert(config->dbh,
+    if (!flatcorrRunInsert(
+	    config->dbh,
             0,      // corr_id
             dvodb,
@@ -184,7 +185,8 @@
             workdir,
             label,
-            NULL,   // stats
             reduction,
-            region
+	    region,
+	    NULL,
+	    0
         )) {
         if (!psDBRollback(config->dbh)) {
@@ -285,7 +287,8 @@
 	workdir,
 	label,
-	NULL,   // stats
 	reduction,
-	region
+	region,
+	NULL, // hostname
+	0 // fault
         );
 
@@ -549,6 +552,20 @@
     PXOPT_LOOKUP_BOOL(simple,  config->args, "-simple",  false);
     PXOPT_LOOKUP_BOOL(limit,   config->args, "-limit",   false);
-
-    char *query = psStringCopy ("SELECT * FROM chipProcessedImfile WHERE chip_id = %" PRId64);
+    
+    psMetadata *where = psMetadataAlloc();
+    PXOPT_COPY_S64(config->args, where, "-chip_id", "chipProcessedImfile.chip_id", "==");
+
+    psString query = pxDataGet("flatcorr_inputimfile.sql");
+    if (!query) {
+        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
+        return false;
+    }
+
+    if (where && psListLength(where->list)) {
+        psString whereClause = psDBGenerateWhereSQL(where, NULL);
+        psStringAppend(&query, " %s", whereClause);
+        psFree(whereClause);
+    }
+    psFree(where);
 
     // treat limit == 0 as "no limit"
@@ -591,10 +608,11 @@
 
     PXOPT_LOOKUP_S64(corr_id, config->args, "-corr_id", true, false);
-
-    if (!setflatcorrRunState(config, corr_id, "full")) {
-        if (!psDBRollback(config->dbh)) {
-            psError(PS_ERR_UNKNOWN, false, "database error");
-        }
-        psError(PS_ERR_UNKNOWN, false, "failed to set run state");
+    PXOPT_LOOKUP_STR(hostname, config->args, "-hostname", false, false);
+    PXOPT_LOOKUP_S16(code, config->args, "-code", false, false);
+
+    char *query = "UPDATE flatcorrRun SET state = 'full', hostname = '%s', fault = '%hd' WHERE corr_id = %" PRId64;
+
+    if (!p_psDBRunQuery(config->dbh, query, hostname, code, corr_id)) {
+        psError(PS_ERR_UNKNOWN, false, "failed to change state for corr_id %" PRId64, corr_id);
         return false;
     }
@@ -636,12 +654,10 @@
 
     char *query = "UPDATE flatcorrRun SET state = '%s' WHERE corr_id = %" PRId64;
+
     if (!p_psDBRunQuery(config->dbh, query, state, corr_id)) {
-        psError(PS_ERR_UNKNOWN, false,
-                "failed to change state for corr_id %" PRId64, corr_id);
-        return false;
-    }
-
-    return true;
-}
-
-
+        psError(PS_ERR_UNKNOWN, false, "failed to change state for corr_id %" PRId64, corr_id);
+        return false;
+    }
+
+    return true;
+}
Index: trunk/ippTools/src/flatcorrConfig.c
===================================================================
--- trunk/ippTools/src/flatcorrConfig.c	(revision 19370)
+++ trunk/ippTools/src/flatcorrConfig.c	(revision 19371)
@@ -92,5 +92,7 @@
     // -addprocess (XXX need to add fault and stats)
     psMetadata *addprocessArgs = psMetadataAlloc();
-    psMetadataAddS64 (addprocessArgs, PS_LIST_TAIL, "-corr_id", 0, "add complete run for specified corr_id (required)", 0);
+    psMetadataAddS64 (addprocessArgs, PS_LIST_TAIL, "-corr_id",  0, "add complete run for specified corr_id (required)", 0);
+    psMetadataAddStr (addprocessArgs, PS_LIST_TAIL, "-hostname", 0, "set hostname", NULL);
+    psMetadataAddS16 (addprocessArgs, PS_LIST_TAIL, "-code",     0, "set fault code", 0);
 
     // -updaterun
