# HG changeset patch # User Adam Chlipala # Date 1220214034 14400 # Node ID b66e692422a409c2cc1adb4711aed08e1b99f2b5 # Parent 35ed669a253fdb5142dc54535bae9d7e6d502056 Monoize COUNT(*) diff -r 35ed669a253f -r b66e692422a4 src/monoize.sml --- 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"), _), _), _), diff -r 35ed669a253f -r b66e692422a4 tests/agg.ur --- 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 Nothing to see here!