src/lib/rqlParse.c 1.3

1.3 2009/12/03 18:00:21 kent
Adding limit clause to RQL parsing.
Index: src/lib/rqlParse.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/lib/rqlParse.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -b -B -U 4 -r1.2 -r1.3
--- src/lib/rqlParse.c	2 Dec 2009 19:14:12 -0000	1.2
+++ src/lib/rqlParse.c	3 Dec 2009 18:00:21 -0000	1.3
@@ -605,16 +605,38 @@
 	}
     else
         tokenizerReuse(tkz);
     }
+
+/* Parse where clause. */
 char *where = tokenizerNext(tkz);
 if (where != NULL)
     {
     if (!sameString(where, "where"))
-        errAbort("Unknown clause '%s' line %d of %s", where, lf->lineIx, lf->fileName);
+	{
+        tokenizerReuse(tkz);
+	}
+    else
+        {
     rql->whereClause = rqlParseExpression(tkz);
     }
+    }
+
+/* Parse limit clause. */
+char *limit = tokenizerNext(tkz);
+rql->limit = -1;	
+if (limit != NULL)
+    {
+    if (!sameString(limit, "limit"))
+        errAbort("Unknown clause '%s' line %d of %s", limit, lf->lineIx, lf->fileName);
+    char *count = tokenizerMustHaveNext(tkz);
+    if (!isdigit(count[0]))
+       errAbort("Expecting number after limit, got %s line %d of %s", 
+       	count, lf->lineIx, lf->fileName);
+    rql->limit = atoi(count);
+    }
 
+/* Check that are at end of statement. */
 char *extra = tokenizerNext(tkz);
 if (extra != NULL)
     errAbort("Extra stuff starting with '%s' past end of statement line %d of %s", 
     	extra, lf->lineIx, lf->fileName);
@@ -623,23 +645,34 @@
 
 void rqlStatementDump(struct rqlStatement *rql, FILE *f)
 /* Print out statement to file. */
 {
-fprintf(f, "%s", rql->command);
+fprintf(f, "%s:", rql->command);
 if (rql->fieldList)
     {
     fprintf(f, " ");
     struct slName *field = rql->fieldList;
     fprintf(f, "%s", field->name);
     for (field = field->next; field != NULL; field = field->next)
         fprintf(f, ",%s", field->name);
     }
+fprintf(f, "\n");
+if (rql->tableList)
+    {
+    fprintf(f, "from: ");
+    struct slName *table = rql->tableList;
+    fprintf(f, "%s", table->name);
+    for (table = table->next; table != NULL; table = table->next)
+        fprintf(f, ",%s", table->name);
+    fprintf(f, "\n");
+    }
 if (rql->whereClause)
     {
     fprintf(f, " where:\n");
     rqlParseDump(rql->whereClause, 0, f);
     }
-fprintf(f, "\n");
+if (rql->limit >= 0)
+    fprintf(f, "limit: %d\n", rql->limit);
 }
 
 static void rqlParseFreeRecursive(struct rqlParse *p)
 /* Depth-first recursive free. */