summaryrefslogtreecommitdiff
path: root/src
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
parentefd10dd6326e15a3841ad0d28ba81bbbadeb304b (diff)
Use COALESCE to hide NULL results of aggregate functions; fix bug with improper ordering of query result columns
Diffstat (limited to 'src')
-rw-r--r--src/cjr_print.sml4
-rw-r--r--src/monoize.sml20
2 files changed, 18 insertions, 6 deletions
diff --git a/src/cjr_print.sml b/src/cjr_print.sml
index fae01db1..f0038de6 100644
--- a/src/cjr_print.sml
+++ b/src/cjr_print.sml
@@ -1657,8 +1657,8 @@ fun p_exp' par env (e, loc) =
map (fn (x', t) => ("__uwf_" ^ ident x ^ ".__uwf_" ^ ident x', t)) xts)
tables
- val outputs = exps @ tables
- val outputs = ListMergeSort.sort (fn ((s1, _), (s2, _)) => String.compare (s1, s2) = GREATER) outputs
+ val sort = ListMergeSort.sort (fn ((s1, _), (s2, _)) => String.compare (s1, s2) = GREATER)
+ val outputs = sort exps @ sort tables
val wontLeakStrings = notLeaky env true state
val wontLeakAnything = notLeaky env false state
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