From 919c2a950ff74af266791e88a258c7ff09be4839 Mon Sep 17 00:00:00 2001 From: Adam Chlipala Date: Thu, 21 Aug 2008 14:09:08 -0400 Subject: GROUP BY and HAVING --- src/lacweb.grm | 14 ++++++++------ src/lacweb.lex | 1 + tests/group_by.lac | 6 ++++++ 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/lacweb.grm b/src/lacweb.grm index c9fe7a6c..dd1cd201 100644 --- a/src/lacweb.grm +++ b/src/lacweb.grm @@ -152,7 +152,7 @@ fun sql_unary (oper, sqlexp, loc) = | NOTAGS of string | BEGIN_TAG of string | END_TAG of string - | SELECT | FROM | AS | CWHERE | GROUP | BY + | SELECT | FROM | AS | CWHERE | GROUP | BY | HAVING | TRUE | FALSE | CAND | OR | NOT | NE | LT | LE | GT | GE @@ -231,6 +231,7 @@ fun sql_unary (oper, sqlexp, loc) = | groupi of group_item | groupis of group_item list | gopt of group_item list option + | hopt of exp %verbose (* print summary of errors *) @@ -645,7 +646,7 @@ attrv : INT (EPrim (Prim.Int INT), s (INTleft, INTri query : query1 (query1) -query1 : SELECT select FROM tables wopt gopt +query1 : SELECT select FROM tables wopt gopt hopt (let val loc = s (SELECTleft, tablesright) @@ -690,10 +691,6 @@ query1 : SELECT select FROM tables wopt gopt (CRecord tabs, loc)), loc) end - val hopt = (sql_inject (EVar (["Basis"], "True"), - EVar (["Basis"], "sql_bool"), - loc)) - val e = (EVar (["Basis"], "sql_query"), loc) val re = (ERecord [((CName "From", loc), (ERecord tables, loc)), @@ -788,3 +785,8 @@ groupis: groupi ([groupi]) gopt : (NONE) | GROUP BY groupis (SOME groupis) + +hopt : (sql_inject (EVar (["Basis"], "True"), + EVar (["Basis"], "sql_bool"), + ErrorMsg.dummySpan)) + | HAVING sqlexp (sqlexp) diff --git a/src/lacweb.lex b/src/lacweb.lex index 0a7d2433..5c8b9d11 100644 --- a/src/lacweb.lex +++ b/src/lacweb.lex @@ -297,6 +297,7 @@ notags = [^<{\n]+; "WHERE" => (Tokens.CWHERE (pos yypos, pos yypos + size yytext)); "GROUP" => (Tokens.GROUP (pos yypos, pos yypos + size yytext)); "BY" => (Tokens.BY (pos yypos, pos yypos + size yytext)); + "HAVING" => (Tokens.HAVING (pos yypos, pos yypos + size yytext)); "TRUE" => (Tokens.TRUE (pos yypos, pos yypos + size yytext)); "FALSE" => (Tokens.FALSE (pos yypos, pos yypos + size yytext)); diff --git a/tests/group_by.lac b/tests/group_by.lac index 2b5d4dd1..50cf553a 100644 --- a/tests/group_by.lac +++ b/tests/group_by.lac @@ -3,3 +3,9 @@ table t2 : {A : float, D : int} val q1 = (SELECT * FROM t1 GROUP BY t1.B) val q2 = (SELECT * FROM t1, t2 GROUP BY t1.B, t2.D, t1.A) + +val q3 = (SELECT * FROM t1 WHERE t1.A = 0 GROUP BY t1.B) +val q4 = (SELECT * FROM t1 WHERE t1.A = 0 GROUP BY t1.C HAVING t1.C < 0.2) + +val q5 = (SELECT t1.A, t2.D FROM t1, t2 GROUP BY t2.D, t1.A) +val q6 = (SELECT t1.A, t2.D FROM t1, t2 WHERE t1.C = 0.0 GROUP BY t2.D, t1.A HAVING t1.A = 0 AND t2.D = 17) -- cgit v1.2.3