diff options
author | Adam Chlipala <adamc@hcoop.net> | 2010-02-25 14:55:35 -0500 |
---|---|---|
committer | Adam Chlipala <adamc@hcoop.net> | 2010-02-25 14:55:35 -0500 |
commit | 131417196382721a2ac982b71b65d3851eb0d929 (patch) | |
tree | 858682c59acf239f88de1874a1282cbed9e925b7 /src/monoize.sml | |
parent | 75b680a703604f97a903c30bb4a50d39d9910aef (diff) |
Use COALESCE to hide NULL results of aggregate functions; fix bug with improper ordering of query result columns
Diffstat (limited to 'src/monoize.sml')
-rw-r--r-- | src/monoize.sml | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/src/monoize.sml b/src/monoize.sml index 21624ab6..0e122c29 100644 --- a/src/monoize.sml +++ b/src/monoize.sml @@ -2358,7 +2358,7 @@ fun monoExp (env, st, fm) (all as (e, loc)) = (L.EFfi ("Basis", "sql_count"), _), _), _), _), _), - _) => ((L'.EPrim (Prim.String "COUNT(*)"), loc), + _) => ((L'.EPrim (Prim.String "COALESCE(COUNT(*),0)"), loc), fm) | L.ECApp ( @@ -2369,17 +2369,29 @@ fun monoExp (env, st, fm) (all as (e, loc)) = _), _), _), _), _), _), - _) => + t) => let + val default = + case #1 t of + L.CFfi ("Basis", s) => + (case s of + "int" => "0" + | "float" => "0.0" + | "string" => "''" + | "time" => "0" + | _ => raise Fail "Illegal type of sql_aggregate [1]") + | _ => raise Fail "Illegal type of sql_aggregate [2]" + val s = (L'.TFfi ("Basis", "string"), loc) fun sc s = (L'.EPrim (Prim.String s), loc) in ((L'.EAbs ("c", s, (L'.TFun (s, (L'.TFun (s, s), loc)), loc), (L'.EAbs ("e1", s, (L'.TFun (s, s), loc), - strcat [(L'.ERel 1, loc), + strcat [sc "COALESCE(", + (L'.ERel 1, loc), sc "(", (L'.ERel 0, loc), - sc ")"]), loc)), loc), + sc (")," ^ default ^ ")")]), loc)), loc), fm) end |