changeset 265:b66e692422a4

Monoize COUNT(*)
author Adam Chlipala <adamc@hcoop.net>
date Sun, 31 Aug 2008 16:20:34 -0400
parents 35ed669a253f
children 7a7efbb3e354
files src/monoize.sml tests/agg.ur
diffstat 2 files changed, 31 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/src/monoize.sml	Sun Aug 31 16:13:07 2008 -0400
+++ b/src/monoize.sml	Sun Aug 31 16:20:34 2008 -0400
@@ -423,8 +423,9 @@
             val es = List.take (es, length es - 1)
         in
             foldr (fn (e, e') =>
-                      case e of
-                          (L'.EPrim (Prim.String ""), _) => e'
+                      case (e, e') of
+                          ((L'.EPrim (Prim.String ""), _), _) => e'
+                        | (_, (L'.EPrim (Prim.String ""), _)) => e
                         | _ =>
                           (L'.EStrcat (e,
                                        (L'.EStrcat ((L'.EPrim (Prim.String ", "), loc), e'), loc)), loc))
@@ -621,15 +622,12 @@
                                                                     strcat loc [
                                                                     (L'.EField (gf "SelectExps", x), loc),
                                                                     sc (" AS _" ^ x)
-                                                                    ]) sexps),
-                                           case sexps of
-                                               [] => sc ""
-                                             | _ => sc ", ",
-                                           strcatComma loc (map (fn (x, xts) =>
-                                                                    strcatComma loc
-                                                                        (map (fn (x', _) =>
-                                                                                 sc (x ^ "." ^ x'))
-                                                                         xts)) stables),
+                                                                    ]) sexps
+                                                            @ map (fn (x, xts) =>
+                                                                      strcatComma loc
+                                                                                  (map (fn (x', _) =>
+                                                                                           sc (x ^ "." ^ x'))
+                                                                                       xts)) stables),
                                            sc " FROM ",
                                            strcatComma loc (map (fn (x, _) => strcat loc [(L'.EField (gf "From", x), loc),
                                                                                           sc (" AS " ^ x)]) tables),
@@ -918,6 +916,16 @@
           | L.EFfi ("Basis", "sql_intersect") => ((L'.EPrim (Prim.String "INTERSECT"), loc), fm)
           | L.EFfi ("Basis", "sql_except") => ((L'.EPrim (Prim.String "EXCEPT"), loc), fm)
 
+          | L.ECApp (
+            (L.ECApp (
+             (L.ECApp (
+              (L.EFfi ("Basis", "sql_count"), _),
+              _), _),
+             _), _),
+            _) => ((L'.EAbs ("_", (L'.TRecord [], loc), (L'.TFfi ("Basis", "string"), loc),
+                             (L'.EPrim (Prim.String "COUNT(*)"), loc)), loc),
+                   fm)
+            
           | L.EApp (
             (L.ECApp (
              (L.ECApp ((L.EFfi ("Basis", "cdata"), _), _), _),
--- a/tests/agg.ur	Sun Aug 31 16:13:07 2008 -0400
+++ b/tests/agg.ur	Sun Aug 31 16:20:34 2008 -0400
@@ -8,3 +8,15 @@
 
 (*val q5 = (SELECT t1.A FROM t1 GROUP BY t1.B)*)
 val q5 = (SELECT SUM(t1.A) AS X FROM t1 GROUP BY t1.B)
+
+
+datatype list a = Nil | Cons of a * list a
+
+val r1 : transaction (list int) =
+        query q1
+        (fn fs acc => return (Cons (fs.X, acc)))
+        Nil
+
+val main : unit -> transaction page = fn () =>
+        n <- r1;
+        return <html><body>Nothing to see here!</body></html>