Index: /trunk/ippTools/src/pztool.c
===================================================================
--- /trunk/ippTools/src/pztool.c	(revision 15031)
+++ /trunk/ippTools/src/pztool.c	(revision 15032)
@@ -137,4 +137,11 @@
     PS_ASSERT_PTR_NON_NULL(config, false);
 
+    bool status = false;
+    psU64 limit = psMetadataLookupU64(&status, config->args, "-limit");
+    if (!status) {
+        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -limit");
+        return false;
+    }
+
     psString query = psStringCopy(
             "SELECT"
@@ -151,4 +158,11 @@
     }
 
+    // treat limit == 0 as "no limit"
+    if (limit) {
+        psString limitString = psDBGenerateLimitSQL(limit);
+        psStringAppend(&query, " %s", limitString);
+        psFree(limitString);
+    }
+
     if (!p_psDBRunQuery(config->dbh, query)) {
         psError(PS_ERR_UNKNOWN, false, "database error");
@@ -196,4 +210,11 @@
     PS_ASSERT_PTR_NON_NULL(config, false);
 
+    bool status = false;
+    psU64 limit = psMetadataLookupU64(&status, config->args, "-limit");
+    if (!status) {
+        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -limit");
+        return false;
+    }
+
     psString query = psStringCopy(
             "SELECT"
@@ -208,4 +229,11 @@
         psStringAppend(&query, " AND %s", whereClause);
         psFree(whereClause);
+    }
+
+    // treat limit == 0 as "no limit"
+    if (limit) {
+        psString limitString = psDBGenerateLimitSQL(limit);
+        psStringAppend(&query, " %s", limitString);
+        psFree(limitString);
     }
 
@@ -478,5 +506,5 @@
         psS64 exp_id = psDBLastInsertID(config->dbh);
 
-        // insert new pzDoneImfile into newImfile
+        // insert new all pzDoneImfile for the exp into newImfile
         {
             char *query =
@@ -503,12 +531,12 @@
             } 
 
-            // sanity check: we should have inserted only one row
+            // sanity check: we should have inserted at least one row
             psU64 affected = psDBAffectedRows(config->dbh);
-            if (psDBAffectedRows(config->dbh) != 1) {
+            if (psDBAffectedRows(config->dbh) < 1) {
                 // rollback
                 if (!psDBRollback(config->dbh)) {
                     psError(PS_ERR_UNKNOWN, false, "database error");
                 }
-                psError(PS_ERR_UNKNOWN, false, "should have affected 1 row but %" PRIu64 " rows were modified", affected);
+                psError(PS_ERR_UNKNOWN, false, "should have affected at least 1 row but %" PRIu64 " rows were modified", affected);
                 psFree(doneExp);
                 psFree(output);
Index: /trunk/ippTools/src/pztoolConfig.c
===================================================================
--- /trunk/ippTools/src/pztoolConfig.c	(revision 15031)
+++ /trunk/ippTools/src/pztoolConfig.c	(revision 15032)
@@ -66,4 +66,6 @@
     psMetadataAddStr(pendingexpArgs, PS_LIST_TAIL, "-exp_type", 0,
             "define exposure type", NULL); 
+    psMetadataAddU64(pendingexpArgs, PS_LIST_TAIL, "-limit",  0,
+            "limit result set to N items", 0);
     psMetadataAddBool(pendingexpArgs, PS_LIST_TAIL, "-simple", 0,
             "use the simple output format", false);
@@ -79,4 +81,6 @@
     psMetadataAddStr(pendingimfileArgs, PS_LIST_TAIL, "-exp_type", 0,
             "define exposure type", NULL); 
+    psMetadataAddU64(pendingimfileArgs, PS_LIST_TAIL, "-limit",  0,
+            "limit result set to N items", 0);
     psMetadataAddBool(pendingimfileArgs, PS_LIST_TAIL, "-simple", 0,
             "use the simple output format", false);
@@ -85,9 +89,9 @@
     psMetadata *copydoneArgs = psMetadataAlloc();
     psMetadataAddStr(copydoneArgs, PS_LIST_TAIL, "-exp_name", 0,
-            "define exposure ID", NULL); 
+            "define exposure ID (required)", NULL); 
     psMetadataAddStr(copydoneArgs, PS_LIST_TAIL, "-inst", 0,
-            "define camera ID", NULL); 
+            "define camera ID (required)", NULL); 
     psMetadataAddStr(copydoneArgs, PS_LIST_TAIL, "-telescope", 0,
-            "define telescope ID", NULL); 
+            "define telescope ID (required)", NULL); 
     psMetadataAddStr(copydoneArgs, PS_LIST_TAIL, "-class", 0,
             "define class", NULL);
