comparison src/monoize.sml @ 1168:69f1d39d3f2d

Use COALESCE to hide NULL results of aggregate functions; fix bug with improper ordering of query result columns
author Adam Chlipala <adamc@hcoop.net>
date Thu, 25 Feb 2010 14:55:35 -0500
parents 32710de7227b
children 983d9b38abc7
comparison
equal deleted inserted replaced
1167:5eca51fcd559 1168:69f1d39d3f2d
2356 (L.ECApp ( 2356 (L.ECApp (
2357 (L.ECApp ( 2357 (L.ECApp (
2358 (L.EFfi ("Basis", "sql_count"), _), 2358 (L.EFfi ("Basis", "sql_count"), _),
2359 _), _), 2359 _), _),
2360 _), _), 2360 _), _),
2361 _) => ((L'.EPrim (Prim.String "COUNT(*)"), loc), 2361 _) => ((L'.EPrim (Prim.String "COALESCE(COUNT(*),0)"), loc),
2362 fm) 2362 fm)
2363 2363
2364 | L.ECApp ( 2364 | L.ECApp (
2365 (L.ECApp ( 2365 (L.ECApp (
2366 (L.ECApp ( 2366 (L.ECApp (
2367 (L.ECApp ( 2367 (L.ECApp (
2368 (L.EFfi ("Basis", "sql_aggregate"), _), 2368 (L.EFfi ("Basis", "sql_aggregate"), _),
2369 _), _), 2369 _), _),
2370 _), _), 2370 _), _),
2371 _), _), 2371 _), _),
2372 _) => 2372 t) =>
2373 let 2373 let
2374 val default =
2375 case #1 t of
2376 L.CFfi ("Basis", s) =>
2377 (case s of
2378 "int" => "0"
2379 | "float" => "0.0"
2380 | "string" => "''"
2381 | "time" => "0"
2382 | _ => raise Fail "Illegal type of sql_aggregate [1]")
2383 | _ => raise Fail "Illegal type of sql_aggregate [2]"
2384
2374 val s = (L'.TFfi ("Basis", "string"), loc) 2385 val s = (L'.TFfi ("Basis", "string"), loc)
2375 fun sc s = (L'.EPrim (Prim.String s), loc) 2386 fun sc s = (L'.EPrim (Prim.String s), loc)
2376 in 2387 in
2377 ((L'.EAbs ("c", s, (L'.TFun (s, (L'.TFun (s, s), loc)), loc), 2388 ((L'.EAbs ("c", s, (L'.TFun (s, (L'.TFun (s, s), loc)), loc),
2378 (L'.EAbs ("e1", s, (L'.TFun (s, s), loc), 2389 (L'.EAbs ("e1", s, (L'.TFun (s, s), loc),
2379 strcat [(L'.ERel 1, loc), 2390 strcat [sc "COALESCE(",
2391 (L'.ERel 1, loc),
2380 sc "(", 2392 sc "(",
2381 (L'.ERel 0, loc), 2393 (L'.ERel 0, loc),
2382 sc ")"]), loc)), loc), 2394 sc (")," ^ default ^ ")")]), loc)), loc),
2383 fm) 2395 fm)
2384 end 2396 end
2385 2397
2386 | L.EFfi ("Basis", "sql_summable_int") => ((L'.ERecord [], loc), fm) 2398 | L.EFfi ("Basis", "sql_summable_int") => ((L'.ERecord [], loc), fm)
2387 | L.EFfi ("Basis", "sql_summable_float") => ((L'.ERecord [], loc), fm) 2399 | L.EFfi ("Basis", "sql_summable_float") => ((L'.ERecord [], loc), fm)