diff options
-rw-r--r-- | src/monoize.sml | 30 | ||||
-rw-r--r-- | tests/agg.ur | 12 |
2 files changed, 31 insertions, 11 deletions
diff --git a/src/monoize.sml b/src/monoize.sml index 920291a6..df606085 100644 --- a/src/monoize.sml +++ b/src/monoize.sml @@ -423,8 +423,9 @@ fun strcatComma loc es = 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 @@ fun monoExp (env, st, fm) (all as (e, loc)) = 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 @@ fun monoExp (env, st, fm) (all as (e, loc)) = | 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 --git a/tests/agg.ur b/tests/agg.ur index 8aa72e6c..dc7c0341 100644 --- a/tests/agg.ur +++ b/tests/agg.ur @@ -8,3 +8,15 @@ val q4 = (SELECT MIN(t1.B) AS X, MAX(t1.A) AS Y FROM t1) (*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> |