Index: trunk/ippTools/src/pxadd.c
===================================================================
--- trunk/ippTools/src/pxadd.c	(revision 28181)
+++ trunk/ippTools/src/pxadd.c	(revision 31375)
@@ -37,5 +37,5 @@
     if (!pxIsValidState(state)) {
         psError(PS_ERR_UNKNOWN, false,
-                "invalid camRun state: %s", state);
+                "invalid stageRun state: %s", state);
         return false;
     }
@@ -51,5 +51,5 @@
 
 
-bool pxaddRunSetStateByQuery(pxConfig *config, psMetadata *where, const char *state)
+bool pxaddRunSetStateByQuery(pxConfig *config, psMetadata *where, const char *stage, const char *state)
 {
     PS_ASSERT_PTR_NON_NULL(config, false);
@@ -59,10 +59,16 @@
     if (!pxIsValidState(state)) {
         psError(PS_ERR_UNKNOWN, false,
-                "invalid chipRun state: %s", state);
+                "invalid stageRun state: %s", state);
         return false;
     }
-
-    psString query = psStringCopy("UPDATE addRun JOIN camRun USING(cam_id) JOIN chipRun USING(chip_id) JOIN rawExp USING(exp_id) SET addRun.state = '%s'");
-
+    psString query = NULL;
+    if (strcmp(stage, "cam") == 0) {
+      query = psStringCopy("UPDATE addRun JOIN camRun USING(cam_id) JOIN chipRun USING(chip_id) JOIN rawExp USING(exp_id) SET addRun.state = '%s'");
+    } 
+    if (strcmp(stage, "stack") == 0) {
+      ///xxx this needs to be fixed
+     
+      /// psString query = psStringCopy("UPDATE addRun JOIN camRun USING(cam_id) JOIN chipRun USING(chip_id) JOIN rawExp USING(exp_id) SET addRun.state = '%s'");
+    } 
     if (where) {
         psString whereClause = psDBGenerateWhereSQL(where, NULL);
@@ -98,9 +104,9 @@
 }
 
-bool pxaddRunSetLabelByQuery(pxConfig *config, psMetadata *where, const char *label)
+bool pxaddRunSetLabelByQuery(pxConfig *config, psMetadata *where, const char *stage, const char *label)
 {
     PS_ASSERT_PTR_NON_NULL(config, false);
     // note label == NULL should be explicitly allowed
-
+    //xxx fix for stack
     psString query = psStringCopy("UPDATE addRun JOIN camRun USING(cam_id) JOIN chipRun USING(chip_id) JOIN rawExp USING(exp_id) SET addRun.label = '%s'");
 
@@ -123,5 +129,6 @@
 
 bool pxaddQueueByCamID(pxConfig *config,
-                       psS64 cam_id,
+		       char *stage,
+                       psS64 stage_id,
                        char *workdir,
                        char *reduction,
@@ -140,6 +147,16 @@
     static psString query = NULL;
     if (!query) {
+      if (strcmp( stage , "cam") == 0) {
         query = pxDataGet("addtool_queue_cam_id.sql");
         psMemSetPersistent(query, true);
+      }
+      if (strcmp(stage,"stack") == 0) {
+	query = pxDataGet("addtool_queue_stack_id.sql");
+        psMemSetPersistent(query, true);
+      }
+      if (strcmp(stage,"staticsky") == 0) {
+	query = pxDataGet("addtool_queue_sky_id.sql");
+        psMemSetPersistent(query, true);
+      }
         if (!query) {
             psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
@@ -148,11 +165,12 @@
     }
 
+    psTrace("addtool.c", PS_LOG_INFO, "pxadd query \n%s\n",query);
     // queue the exp
     // Note: cam_id is being cast here work around psS64 have a different type different
     // on 32/64
     if (!p_psDBRunQueryF(config->dbh, query,
-                         "new", // state
+			 "new", // state
                          workdir  ? workdir   : "NULL",
-                         "dirty", //workdir_state
+			  "dirty", //workdir_state
                          reduction? reduction : "NULL",
                          label    ? label     : "NULL",
@@ -164,5 +182,5 @@
 			 minidvodb_group,
 			 minidvodb_name,
-                         (long long) cam_id
+                         (long long) stage_id
     )) {
       psError(PS_ERR_UNKNOWN, false, "database error %s", query);
