# HG changeset patch # User Adam Chlipala # Date 1219349025 14400 # Node ID a338da9d82f32ee6fa618a88ceb0f57d2e8214fe # Parent eadeea528f753e451f6951a5bf9a048a645a6d9d OFFSET diff -r eadeea528f75 -r a338da9d82f3 lib/basis.lig --- 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}} diff -r eadeea528f75 -r a338da9d82f3 src/lacweb.grm --- 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) diff -r eadeea528f75 -r a338da9d82f3 src/lacweb.lex --- 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 @@ "HAVING" => (Tokens.HAVING (pos yypos, pos yypos + size yytext)); "LIMIT" => (Tokens.LIMIT (pos yypos, pos yypos + size yytext)); "OFFSET" => (Tokens.OFFSET (pos yypos, pos yypos + size yytext)); + "ALL" => (Tokens.ALL (pos yypos, pos yypos + size yytext)); "UNION" => (Tokens.UNION (pos yypos, pos yypos + size yytext)); "INTERSECT" => (Tokens.INTERSECT (pos yypos, pos yypos + size yytext)); diff -r eadeea528f75 -r a338da9d82f3 tests/limit.lac --- 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})