summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adamc@hcoop.net>2008-08-21 14:09:08 -0400
committerGravatar Adam Chlipala <adamc@hcoop.net>2008-08-21 14:09:08 -0400
commit919c2a950ff74af266791e88a258c7ff09be4839 (patch)
tree02d23cc3d6d72e84b9232fd999fa1dd614990ef4
parent4832e63e1f6c7b5bb7c098e371c794111f32f878 (diff)
GROUP BY and HAVING
-rw-r--r--src/lacweb.grm14
-rw-r--r--src/lacweb.lex1
-rw-r--r--tests/group_by.lac6
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]+;
<INITIAL> "WHERE" => (Tokens.CWHERE (pos yypos, pos yypos + size yytext));
<INITIAL> "GROUP" => (Tokens.GROUP (pos yypos, pos yypos + size yytext));
<INITIAL> "BY" => (Tokens.BY (pos yypos, pos yypos + size yytext));
+<INITIAL> "HAVING" => (Tokens.HAVING (pos yypos, pos yypos + size yytext));
<INITIAL> "TRUE" => (Tokens.TRUE (pos yypos, pos yypos + size yytext));
<INITIAL> "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)