2462760a02e47839b89ec632d331f78b894deef2
kent
  Wed Jun 14 09:47:00 2017 -0700
Respecting limit clause.

diff --git src/tabFile/tabQuery/tabQuery.c src/tabFile/tabQuery/tabQuery.c
index 4aed2d0..8a2cc20 100644
--- src/tabFile/tabQuery/tabQuery.c
+++ src/tabFile/tabQuery/tabQuery.c
@@ -96,45 +96,47 @@
     {
     printf("#");
     char *sep = "";
     for (field = rql->fieldList; field != NULL; field = field->next)
 	{
 	printf("%s%s", sep, field->name);
 	sep = "\t";
 	}
     printf("\n");
     }
 
 /* Print out or just count selected fields that match query */
 int matchCount = 0;
 struct lm *lm = lmInit(0);
 struct fieldedRow *row;
+int limit = rql->limit;
 for (row = gTable->rowList; row != NULL; row = row->next)
     {
     boolean pass = TRUE;
     if (rql->whereClause != NULL)
         {
 	struct rqlEval res = rqlEvalOnRecord(rql->whereClause, row, lookup, lm);
 	res = rqlEvalCoerceToBoolean(res);
 	pass = res.val.b;
 	}
     if (pass)
         {
-	if (doCount)
 	++matchCount;
-	else
+	if (!doCount)
 	    {
+	    if (limit != 0 && matchCount > limit)
+	        break;
 	    char *sep = "";
 	    for (field = rql->fieldList; field != NULL; field = field->next)
 		{
 		int fieldIx = hashIntVal(gFieldHash, field->name);
 		printf("%s%s", sep, row->row[fieldIx]);
 		sep = "\t";
 		}
 	    printf("\n");
 	    }
 	}
     }
 
 if (doCount)
     printf("%d\n", matchCount);
 }