Index: trunk/ippTools/src/warptool.c
===================================================================
--- trunk/ippTools/src/warptool.c	(revision 11776)
+++ trunk/ippTools/src/warptool.c	(revision 11777)
@@ -945,12 +945,20 @@
     PS_ASSERT_PTR_NON_NULL(config, false);
 
-    psString query = psStringCopy(
-        " SELECT DISTINCT"
-        "   p4Scfile.*"
-        " FROM p4Run"
-        " JOIN p4Scfile"
-        "   USING(p4_id)"
-        " WHERE"
-        "   p4Run.state = 'run'"
+    bool status = false;
+    psU64 limit = psMetadataLookupU64(&status, config->args, "-limit");
+    if (!status) {
+        psError(PXTOOLS_ERR_PROG, false, "failed to lookup value for -limit");
+        return false;
+    }
+
+    // find all rawImfiles matching the default query
+    psString query = psStringCopy( 
+        "SELECT\n"
+        "   p4Scfile.*\n"
+        " FROM p4Run\n"
+        " JOIN p4Scfile\n"
+        "   USING(p4_id)\n"
+        " WHERE\n"
+        "   p4Run.state = 'run'\n" 
     );
 
@@ -961,4 +969,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");
@@ -970,5 +985,14 @@
     psArray *output = p_psDBFetchResult(config->dbh);
     if (!output) {
-        psError(PS_ERR_UNKNOWN, false, "database error");
+        psErrorCode err = psErrorCodeLast();
+        switch (err) {
+            case PS_ERR_DB_CLIENT:
+                psError(PXTOOLS_ERR_SYS, false, "database error");
+            case PS_ERR_DB_SERVER:
+                psError(PXTOOLS_ERR_PROG, false, "database error");
+            default:
+                psError(PXTOOLS_ERR_PROG, false, "unknown error");
+        }
+
         return false;
     }
@@ -989,9 +1013,11 @@
     }
 
-    // negative simple so the default is true
-    if (!ippdbPrintMetadatas(stdout, output, "p4Scfile", !simple)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to print array");
-        psFree(output);
-        return false;
+    if (psArrayLength(output)) {
+        // negative simple so the default is true
+        if (!ippdbPrintMetadatas(stdout, output, "p4Scfile", !simple)) {
+            psError(PS_ERR_UNKNOWN, false, "failed to print array");
+            psFree(output);
+            return false;
+        }
     }
 
