Index: trunk/ippTools/src/pzgetimfiles.c
===================================================================
--- trunk/ippTools/src/pzgetimfiles.c	(revision 10063)
+++ trunk/ippTools/src/pzgetimfiles.c	(revision 10118)
@@ -26,4 +26,5 @@
 #include <stdlib.h>
 
+#include "pxtag.h"
 #include "pxtools.h"
 #include "pzgetimfiles.h"
@@ -361,8 +362,18 @@
     // copy the summitExp row into newExp in order to create a new exp_tag
     {
+        psString exp_tag = pxGenExpTag(config, filesetid);
+        if (!exp_tag) {
+            // rollback
+            if (!psDBRollback(config->dbh)) {
+                psError(PS_ERR_UNKNOWN, false, "database error");
+            }
+            psError(PS_ERR_UNKNOWN, false, "database error");
+            return false;
+        }
+
         char *query = 
             "INSERT INTO newExp" 
             "   SElECT"
-            "       NULL," // exp_tag
+            "       '%s'," // exp_tag
             "       summitExp.exp_id,"
             "       summitExp.camera,"
@@ -377,12 +388,14 @@
             "       AND summitExp.telescope = '%s'";
 
-        if (!p_psDBRunQuery(config->dbh, query)) {
-            // rollback
-            if (!psDBRollback(config->dbh)) {
-                psError(PS_ERR_UNKNOWN, false, "database error");
-            }
-            psError(PS_ERR_UNKNOWN, false, "database error");
-            return false;
-        }
+        if (!p_psDBRunQuery(config->dbh, query, exp_tag, filesetid, camera, telescope)) {
+            // rollback
+            if (!psDBRollback(config->dbh)) {
+                psError(PS_ERR_UNKNOWN, false, "database error");
+            }
+            psError(PS_ERR_UNKNOWN, false, "database error");
+            psFree(exp_tag);
+            return false;
+        }
+        psFree(exp_tag);
 
         // sanity check: we should have inserted only one row
@@ -403,10 +416,13 @@
         char *query = 
             "UPDATE pzPendingImfile"
-            " SET exp_tag = LAST_INSERT_ID()"
+            " SET exp_tag = (SELECT exp_tag from newExp"
+            "                WHERE exp_id = '%s'"
+            "                AND camera = '%s'"
+            "                AND telescope = '%s')"
             " WHERE"
             "   exp_id = '%s'"
             "   AND camera = '%s'"
             "   AND telescope = '%s'";
-        if (!p_psDBRunQuery(config->dbh, query, filesetid, camera, telescope)) {
+        if (!p_psDBRunQuery(config->dbh, query, filesetid, camera, telescope, filesetid, camera, telescope)) {
             // rollback
             if (!psDBRollback(config->dbh)) {
