changeset 232:a338da9d82f3

OFFSET
author Adam Chlipala <adamc@hcoop.net>
date Thu, 21 Aug 2008 16:03:45 -0400
parents eadeea528f75
children c466678af854
files lib/basis.lig src/lacweb.grm src/lacweb.lex tests/limit.lac
diffstat 4 files changed, 24 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/lib/basis.lig	Thu Aug 21 16:00:01 2008 -0400
+++ b/lib/basis.lig	Thu Aug 21 16:03:45 2008 -0400
@@ -64,11 +64,16 @@
 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}}
--- a/src/lacweb.grm	Thu Aug 21 16:00:01 2008 -0400
+++ b/src/lacweb.grm	Thu Aug 21 16:03:45 2008 -0400
@@ -164,7 +164,7 @@
 
  | 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 @@
  | obopt of exp
  | obexps of exp
  | lopt of exp
+ | ofopt of exp
  | sqlint of exp
 
 
@@ -661,7 +662,7 @@
        | 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 @@
                                                                 ((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 @@
                                          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)
--- a/src/lacweb.lex	Thu Aug 21 16:00:01 2008 -0400
+++ b/src/lacweb.lex	Thu Aug 21 16:03:45 2008 -0400
@@ -311,6 +311,7 @@
 <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));
--- a/tests/limit.lac	Thu Aug 21 16:00:01 2008 -0400
+++ b/tests/limit.lac	Thu Aug 21 16:03:45 2008 -0400
@@ -2,3 +2,6 @@
 
 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})