changeset 235:0608a0cfd32a

COUNT
author Adam Chlipala <adamc@hcoop.net>
date Thu, 28 Aug 2008 11:59:46 -0400
parents 82409ef72019
children f5732dc1316c
files lib/basis.lig src/lacweb.grm src/lacweb.lex tests/agg.lac
diffstat 4 files changed, 18 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/lib/basis.lig	Thu Aug 28 11:49:38 2008 -0400
+++ b/lib/basis.lig	Thu Aug 28 11:59:46 2008 -0400
@@ -125,6 +125,10 @@
         -> sql_exp tables agg exps t -> sql_exp tables agg exps t
         -> sql_exp tables agg exps bool
 
+val sql_count : tables ::: {{Type}} -> agg ::: {{Type}} -> exps ::: {Type}
+        -> unit -> sql_exp tables agg exps int
+
+
 (** XML *)
 
 con tag :: {Type} -> {Unit} -> {Unit} -> {Type} -> {Type} -> Type
--- a/src/lacweb.grm	Thu Aug 28 11:49:38 2008 -0400
+++ b/src/lacweb.grm	Thu Aug 28 11:59:46 2008 -0400
@@ -169,6 +169,7 @@
  | UNION | INTERSECT | EXCEPT
  | LIMIT | OFFSET | ALL
  | TRUE | FALSE | CAND | OR | NOT
+ | COUNT
  | NE | LT | LE | GT | GE
 
 %nonterm
@@ -824,6 +825,13 @@
                                                      s (LBRACEleft, RBRACEright)))
        | LPAREN sqlexp RPAREN           (sqlexp)
 
+       | COUNT LPAREN STAR RPAREN       (let
+                                             val loc = s (COUNTleft, RPARENright)
+                                         in
+                                             (EApp ((EVar (["Basis"], "sql_count"), loc),
+                                                    (ERecord [], loc)), loc)
+                                         end)
+
 wopt   :                                (sql_inject (EVar (["Basis"], "True"),
                                                      EVar (["Basis"], "sql_bool"),
                                                      dummy))
--- a/src/lacweb.lex	Thu Aug 28 11:49:38 2008 -0400
+++ b/src/lacweb.lex	Thu Aug 28 11:59:46 2008 -0400
@@ -323,6 +323,8 @@
 <INITIAL> "OR"        => (Tokens.OR (pos yypos, pos yypos + size yytext));
 <INITIAL> "NOT"       => (Tokens.NOT (pos yypos, pos yypos + size yytext));
 
+<INITIAL> "COUNT"     => (Tokens.COUNT (pos yypos, pos yypos + size yytext));
+
 <INITIAL> {id}        => (Tokens.SYMBOL (yytext, pos yypos, pos yypos + size yytext));
 <INITIAL> {cid}       => (Tokens.CSYMBOL (yytext, pos yypos, pos yypos + size yytext));
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/agg.lac	Thu Aug 28 11:59:46 2008 -0400
@@ -0,0 +1,4 @@
+table t1 : {A : int, B : string, C : float}
+table t2 : {A : float, D : int}
+
+val q1 = (SELECT COUNT( * ) AS N FROM t1)