changeset 262:a6cb33f49366

Monoize LIMIT
author Adam Chlipala <adamc@hcoop.net>
date Sun, 31 Aug 2008 16:10:20 -0400
parents ee51e9d35c9b
children 02e1870a0516
files src/monoize.sml tests/limit.ur
diffstat 2 files changed, 31 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/monoize.sml	Sun Aug 31 16:03:43 2008 -0400
+++ b/src/monoize.sml	Sun Aug 31 16:10:20 2008 -0400
@@ -739,6 +739,17 @@
 
           | L.EFfi ("Basis", "sql_no_limit") =>
             ((L'.EPrim (Prim.String ""), loc), fm)
+          | L.EFfiApp ("Basis", "sql_limit", [e]) =>
+            let
+                val (e, fm) = monoExp (env, st, fm) e
+            in
+                (strcat loc [
+                 (L'.EPrim (Prim.String " LIMIT "), loc),
+                 (L'.EFfiApp ("Basis", "sqlifyInt", [e]), loc)
+                 ],
+                 fm)
+            end
+
           | L.EFfi ("Basis", "sql_no_offset") =>
             ((L'.EPrim (Prim.String ""), loc), fm)
 
--- a/tests/limit.ur	Sun Aug 31 16:03:43 2008 -0400
+++ b/tests/limit.ur	Sun Aug 31 16:10:20 2008 -0400
@@ -5,3 +5,23 @@
 
 val q3 = (SELECT * FROM t OFFSET 3)
 val q4 = fn n => fn m => (SELECT * FROM t LIMIT {n} OFFSET {m})
+
+
+datatype list a = Nil | Cons of a * list a
+
+val r1 : transaction (list {A : int, B : string, C : float}) =
+        query (q2 3)
+        (fn fs acc => return (Cons (fs.T, acc)))
+        Nil
+
+val r2 : transaction string =
+        ls <- r1;
+        return (case ls of
+                    Nil => "Problem"
+                  | Cons ({B = b, ...}, _) => b)
+
+val main : unit -> transaction page = fn () =>
+        s <- r2;
+        return <html><body>
+                {cdata s}
+        </body></html>