Index: trunk/ippTools/src/pztool.c
===================================================================
--- trunk/ippTools/src/pztool.c	(revision 30907)
+++ trunk/ippTools/src/pztool.c	(revision 31038)
@@ -53,5 +53,5 @@
 static psArray *pzGetPendingCameras(pxConfig *config);
 static psArray *pzArrayZip(psArray *arraySet, psS64 limit);
-static bool pzDownloadExpSetState(pxConfig *config, const char *exp_name, const char *camera, const char *telescope, const char *state);
+static bool pzDownloadExpSetState(pxConfig *config, const psS64 summit_id, const char *state);
 
 # define MODECASE(caseName, func) \
@@ -222,4 +222,5 @@
 
     psMetadata *where = psMetadataAlloc();
+    PXOPT_COPY_S64(config->args, where,  "-summit_id",    "summit_id", "==");
     PXOPT_COPY_STR(config->args, where,  "-exp_name",     "exp_name", "==");
     PXOPT_COPY_STR(config->args, where,  "-inst",         "camera", "==");
@@ -237,9 +238,7 @@
             " FROM summitExp"
             " LEFT JOIN pzDownloadExp"
-            "   USING(exp_name, camera, telescope)"
+	    "   USING(summit_id)"
             " WHERE"
-            "   pzDownloadExp.exp_name IS NULL"
-            "   AND pzDownloadExp.camera IS NULL"
-            "   AND pzDownloadExp.telescope IS NULL"
+	    "   pzDownloadExp.summit_id IS NULL"
             "   AND summitExp.fault = 0"
         );
@@ -260,4 +259,5 @@
     if (limit) {
         psString limitString = psDBGenerateLimitSQL(limit);
+
         psStringAppend(&query, " %s", limitString);
         psFree(limitString);
@@ -299,4 +299,5 @@
 
     psMetadata *where = psMetadataAlloc();
+    PXOPT_COPY_S64(config->args, where,  "-summit_id",     "summit_id", "==");
     PXOPT_COPY_STR(config->args, where,  "-exp_name",      "exp_name",  "==");
     PXOPT_COPY_STR(config->args, where,  "-inst",          "camera",    "==");
@@ -401,4 +402,5 @@
 
     // required
+    PXOPT_LOOKUP_S64(summit_id, config->args, "-summit_id", true, false);
     PXOPT_LOOKUP_STR(exp_name, config->args, "-exp_name", true, false);
     PXOPT_LOOKUP_STR(camera, config->args, "-inst", true, false);
@@ -428,4 +430,5 @@
 
         psMetadata *where = psMetadataAlloc();
+	PXOPT_COPY_S64(config->args, where,  "-summit_id", "summit_id", "==");
         PXOPT_COPY_STR(config->args, where,  "-exp_name", "exp_name", "==");
         PXOPT_COPY_STR(config->args, where,  "-inst", "camera", "==");
@@ -459,4 +462,5 @@
 
     if (!pzDownloadImfileInsert(config->dbh,
+            summit_id,			
             exp_name,
             camera,
@@ -505,4 +509,5 @@
 
     psMetadata *where = psMetadataAlloc();
+    PXOPT_COPY_STR(config->args, where,  "-summit_id", "summit_id", "==");
     PXOPT_COPY_STR(config->args, where,  "-exp_name", "exp_name", "==");
     PXOPT_COPY_STR(config->args, where,  "-inst", "camera", "==");
@@ -560,4 +565,5 @@
 
     // required
+    PXOPT_LOOKUP_S64(summit_id, config->args, "-summit_id", true, false);
     PXOPT_LOOKUP_STR(exp_name, config->args, "-exp_name", true, false);
     PXOPT_LOOKUP_STR(inst, config->args, "-inst", true, false);
@@ -579,4 +585,5 @@
     if (!newExpInsert(config->dbh,
             0x0,        // exp_id
+	    summit_id,  // summit_id
             exp_name,   // tmp_exp_name
             inst,       // tmp_camera
@@ -597,12 +604,13 @@
         }
 
-        psS64 exp_id = psDBLastInsertID(config->dbh);
-
-        // insert newImfiles
-        {
-            char *query =
+    psS64 exp_id = psDBLastInsertID(config->dbh);
+
+    // insert newImfiles
+    {
+      char *query =
                 "INSERT INTO newImfile"
-                "   SElECT"
+                "   SELECT"
                 "       %" PRId64 ","               // exp_id
+	        "       %" PRId64 ","               // summit_id
                 "       pzDownloadImfile.class_id," // tmp_class_id
                 "       pzDownloadImfile.uri,"      // uri
@@ -616,20 +624,20 @@
                 "       AND pzDownloadImfile.telescope = '%s'";
 
-        if (!p_psDBRunQueryF(config->dbh, query, exp_id, exp_name, inst, telescope)) {
-            psError(PS_ERR_UNKNOWN, false, "database error");
-            return false;
-        }
-
-        // sanity check: we should have inserted at least one row
-        psU64 affected = psDBAffectedRows(config->dbh);
-        if (psDBAffectedRows(config->dbh) < 1) {
-            psError(PS_ERR_UNKNOWN, false, "should have affected at least 1 row but %" PRIu64 " rows were modified", affected);
-            return false;
-        }
+      if (!p_psDBRunQueryF(config->dbh, query, exp_id, summit_id, exp_name, inst, telescope)) {
+	psError(PS_ERR_UNKNOWN, false, "database error");
+	return false;
+      }
+
+      // sanity check: we should have inserted at least one row
+      psU64 affected = psDBAffectedRows(config->dbh);
+      if (psDBAffectedRows(config->dbh) < 1) {
+	psError(PS_ERR_UNKNOWN, false, "should have affected at least 1 row but %" PRIu64 " rows were modified", affected);
+	return false;
+      }
     }
 
     // set pzDownloadExp.state to 'stop'
-    if (!pzDownloadExpSetState(config, exp_name, inst, telescope, "stop")) {
-        psError(PS_ERR_UNKNOWN, false, "failed to change pzDownloadExp.state for %s:%s:%s", exp_name, inst, telescope);
+    if (!pzDownloadExpSetState(config, summit_id, "stop")) {
+        psError(PS_ERR_UNKNOWN, false, "failed to change pzDownloadExp.state for %ld", summit_id);
         return false;
     }
@@ -887,5 +895,5 @@
 
 
-static bool pzDownloadExpSetState(pxConfig *config, const char *exp_name, const char *camera, const char *telescope, const char *state)
+static bool pzDownloadExpSetState(pxConfig *config, const psS64 summit_id, const char *state)
 {
     PS_ASSERT_PTR_NON_NULL(state, false);
@@ -904,7 +912,7 @@
     }
 
-    char *query = "UPDATE pzDownloadExp SET state = '%s' WHERE exp_name = '%s' and camera = '%s' and telescope = '%s'";
-    if (!p_psDBRunQueryF(config->dbh, query, state, exp_name, camera, telescope)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to change state for %s:%s:%s", exp_name, camera, telescope);
+    char *query = "UPDATE pzDownloadExp SET state = '%s' WHERE summit_id = %ld";
+    if (!p_psDBRunQueryF(config->dbh, query, state, summit_id)) {
+        psError(PS_ERR_UNKNOWN, false, "failed to change state for %ld", summit_id);
         return false;
     }
@@ -916,11 +924,9 @@
 {
   PS_ASSERT_PTR_NON_NULL(config, false);
-  PXOPT_LOOKUP_STR(exp_name, config->args, "-exp_name", true, false);
-  PXOPT_LOOKUP_STR(camera,   config->args, "-inst",   true, false);
-  PXOPT_LOOKUP_STR(telescope,config->args, "-telescope",true, false);
+  PXOPT_LOOKUP_S64(summit_id, config->args, "-summit_id", true, false);
   PXOPT_LOOKUP_STR(state,    config->args, "-set_state",true, false);
 
-  if (!pzDownloadExpSetState(config,exp_name,camera,telescope,state)) {
-    psError(PS_ERR_UNKNOWN, false, "failed to change state for %s:%s:%s", exp_name, camera, telescope);
+  if (!pzDownloadExpSetState(config,summit_id, state)) {
+    psError(PS_ERR_UNKNOWN, false, "failed to change state for %ld", summit_id);
     return false;
   }
