diff options
-rw-r--r-- | lib/basis.lig | 7 | ||||
-rw-r--r-- | src/lacweb.grm | 19 | ||||
-rw-r--r-- | src/lacweb.lex | 2 | ||||
-rw-r--r-- | tests/limit.lac | 4 |
4 files changed, 29 insertions, 3 deletions
diff --git a/lib/basis.lig b/lib/basis.lig index 863debcb..3b77a1af 100644 --- a/lib/basis.lig +++ b/lib/basis.lig @@ -60,10 +60,15 @@ val sql_order_by_Cons : tables ::: {{Type}} -> t ::: Type -> sql_exp tables [] t -> sql_order_by tables -> sql_order_by tables +type sql_limit +val sql_no_limit : sql_limit +val sql_limit : int -> sql_limit + val sql_query : tables ::: {{Type}} -> selected ::: {{Type}} -> {Rows : sql_query1 tables selected, - OrderBy : sql_order_by tables} + OrderBy : sql_order_by tables, + Limit : sql_limit} -> 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 b4256f30..0809842d 100644 --- a/src/lacweb.grm +++ b/src/lacweb.grm @@ -164,6 +164,7 @@ fun sql_relop (oper, sqlexp1, sqlexp2, loc) = | SELECT | FROM | AS | CWHERE | GROUP | ORDER | BY | HAVING | UNION | INTERSECT | EXCEPT + | LIMIT | OFFSET | TRUE | FALSE | CAND | OR | NOT | NE | LT | LE | GT | GE @@ -245,6 +246,8 @@ fun sql_relop (oper, sqlexp1, sqlexp2, loc) = | hopt of exp | obopt of exp | obexps of exp + | lopt of exp + | sqlint of exp %verbose (* print summary of errors *) @@ -658,13 +661,15 @@ attrv : INT (EPrim (Prim.Int INT), s (INTleft, INTri | STRING (EPrim (Prim.String STRING), s (STRINGleft, STRINGright)) | LBRACE eexp RBRACE (eexp) -query : query1 obopt (let +query : query1 obopt lopt (let val loc = s (query1left, query1right) val re = (ERecord [((CName "Rows", loc), query1), ((CName "OrderBy", loc), - obopt)], loc) + obopt), + ((CName "Limit", loc), + lopt)], loc) in (EApp ((EVar (["Basis"], "sql_query"), loc), re), loc) end) @@ -844,3 +849,13 @@ obexps : sqlexp (let in (EApp (e, obexps), loc) end) + +lopt : (EVar (["Basis"], "sql_no_limit"), dummy) + | LIMIT sqlint (let + val loc = s (LIMITleft, sqlintright) + in + (EApp ((EVar (["Basis"], "sql_limit"), 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 5c87ae17..8ec07c41 100644 --- a/src/lacweb.lex +++ b/src/lacweb.lex @@ -309,6 +309,8 @@ notags = [^<{\n]+; <INITIAL> "ORDER" => (Tokens.ORDER (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> "LIMIT" => (Tokens.LIMIT (pos yypos, pos yypos + size yytext)); +<INITIAL> "OFFSET" => (Tokens.OFFSET (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 new file mode 100644 index 00000000..47c6bff4 --- /dev/null +++ b/tests/limit.lac @@ -0,0 +1,4 @@ +table t : {A : int, B : string, C : float} + +val q1 = (SELECT * FROM t LIMIT 42) +val q2 = fn n => (SELECT * FROM t LIMIT {n}) |