summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adamc@hcoop.net>2008-08-21 16:03:45 -0400
committerGravatar Adam Chlipala <adamc@hcoop.net>2008-08-21 16:03:45 -0400
commita8a9ea33b3e9b7d072f0843ba3bb709a4a3eb7a9 (patch)
treed14fa20d4fc3425da7e101a034526dd98dd22d1a
parent535d72045b35d01cf4513af273262c3c50c219fe (diff)
OFFSET
-rw-r--r--lib/basis.lig7
-rw-r--r--src/lacweb.grm17
-rw-r--r--src/lacweb.lex1
-rw-r--r--tests/limit.lac3
4 files changed, 24 insertions, 4 deletions
diff --git a/lib/basis.lig b/lib/basis.lig
index 3b77a1af..b85587bb 100644
--- a/lib/basis.lig
+++ b/lib/basis.lig
@@ -64,11 +64,16 @@ type sql_limit
val sql_no_limit : sql_limit
val sql_limit : int -> sql_limit
+type sql_offset
+val sql_no_offset : sql_offset
+val sql_offset : int -> sql_offset
+
val sql_query : tables ::: {{Type}}
-> selected ::: {{Type}}
-> {Rows : sql_query1 tables selected,
OrderBy : sql_order_by tables,
- Limit : sql_limit}
+ Limit : sql_limit,
+ Offset : sql_offset}
-> sql_query selected
val sql_field : otherTabs ::: {{Type}} -> otherFields ::: {Type} -> fieldType ::: Type -> agg ::: {{Type}}
diff --git a/src/lacweb.grm b/src/lacweb.grm
index 0809842d..4352fa8c 100644
--- a/src/lacweb.grm
+++ b/src/lacweb.grm
@@ -164,7 +164,7 @@ fun sql_relop (oper, sqlexp1, sqlexp2, loc) =
| SELECT | FROM | AS | CWHERE | GROUP | ORDER | BY | HAVING
| UNION | INTERSECT | EXCEPT
- | LIMIT | OFFSET
+ | LIMIT | OFFSET | ALL
| TRUE | FALSE | CAND | OR | NOT
| NE | LT | LE | GT | GE
@@ -247,6 +247,7 @@ fun sql_relop (oper, sqlexp1, sqlexp2, loc) =
| obopt of exp
| obexps of exp
| lopt of exp
+ | ofopt of exp
| sqlint of exp
@@ -661,7 +662,7 @@ attrv : INT (EPrim (Prim.Int INT), s (INTleft, INTri
| STRING (EPrim (Prim.String STRING), s (STRINGleft, STRINGright))
| LBRACE eexp RBRACE (eexp)
-query : query1 obopt lopt (let
+query : query1 obopt lopt ofopt (let
val loc = s (query1left, query1right)
val re = (ERecord [((CName "Rows", loc),
@@ -669,7 +670,9 @@ query : query1 obopt lopt (let
((CName "OrderBy", loc),
obopt),
((CName "Limit", loc),
- lopt)], loc)
+ lopt),
+ ((CName "Offset", loc),
+ ofopt)], loc)
in
(EApp ((EVar (["Basis"], "sql_query"), loc), re), loc)
end)
@@ -851,11 +854,19 @@ obexps : sqlexp (let
end)
lopt : (EVar (["Basis"], "sql_no_limit"), dummy)
+ | LIMIT ALL (EVar (["Basis"], "sql_no_limit"), dummy)
| LIMIT sqlint (let
val loc = s (LIMITleft, sqlintright)
in
(EApp ((EVar (["Basis"], "sql_limit"), loc), sqlint), loc)
end)
+ofopt : (EVar (["Basis"], "sql_no_offset"), dummy)
+ | OFFSET sqlint (let
+ val loc = s (OFFSETleft, sqlintright)
+ in
+ (EApp ((EVar (["Basis"], "sql_offset"), loc), sqlint), loc)
+ end)
+
sqlint : INT (EPrim (Prim.Int INT), s (INTleft, INTright))
| LBRACE eexp RBRACE (eexp)
diff --git a/src/lacweb.lex b/src/lacweb.lex
index 8ec07c41..f67eada7 100644
--- a/src/lacweb.lex
+++ b/src/lacweb.lex
@@ -311,6 +311,7 @@ notags = [^<{\n]+;
<INITIAL> "HAVING" => (Tokens.HAVING (pos yypos, pos yypos + size yytext));
<INITIAL> "LIMIT" => (Tokens.LIMIT (pos yypos, pos yypos + size yytext));
<INITIAL> "OFFSET" => (Tokens.OFFSET (pos yypos, pos yypos + size yytext));
+<INITIAL> "ALL" => (Tokens.ALL (pos yypos, pos yypos + size yytext));
<INITIAL> "UNION" => (Tokens.UNION (pos yypos, pos yypos + size yytext));
<INITIAL> "INTERSECT" => (Tokens.INTERSECT (pos yypos, pos yypos + size yytext));
diff --git a/tests/limit.lac b/tests/limit.lac
index 47c6bff4..5bfb1a81 100644
--- a/tests/limit.lac
+++ b/tests/limit.lac
@@ -2,3 +2,6 @@ table t : {A : int, B : string, C : float}
val q1 = (SELECT * FROM t LIMIT 42)
val q2 = fn n => (SELECT * FROM t LIMIT {n})
+
+val q3 = (SELECT * FROM t OFFSET 3)
+val q4 = fn n => fn m => (SELECT * FROM t LIMIT {n} OFFSET {m})