summaryrefslogtreecommitdiff
path: root/src/monoize.sml
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adamc@hcoop.net>2010-02-25 14:55:35 -0500
committerGravatar Adam Chlipala <adamc@hcoop.net>2010-02-25 14:55:35 -0500
commit118054678805f2498b8eac0d4685d6977f4493ae (patch)
tree858682c59acf239f88de1874a1282cbed9e925b7 /src/monoize.sml
parentefd10dd6326e15a3841ad0d28ba81bbbadeb304b (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.sml20
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