summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adam@chlipala.net>2015-07-04 19:24:26 -0400
committerGravatar Adam Chlipala <adam@chlipala.net>2015-07-04 19:24:26 -0400
commit0da7569c8a5bb06dc9dc3a3252be6375a8074a95 (patch)
tree653e081394a5d1bc1c438b42375f1cb17b64db6a /src
parent39f3738e921d520667aab45047972479c6d0ce15 (diff)
Tag NULLs with their types in SQL, to help the DBMS do type inference
Diffstat (limited to 'src')
-rw-r--r--src/monoize.sml15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/monoize.sml b/src/monoize.sml
index bac82f55..8934db2c 100644
--- a/src/monoize.sml
+++ b/src/monoize.sml
@@ -2214,6 +2214,19 @@ fun monoExp (env, st, fm) (all as (e, loc)) =
let
val t = monoType env t
val s = (L'.TFfi ("Basis", "string"), loc)
+
+ fun toSqlType (t : L'.typ) =
+ case #1 t of
+ L'.TFfi ("Basis", "int") => Settings.Int
+ | L'.TFfi ("Basis", "float") => Settings.Float
+ | L'.TFfi ("Basis", "string") => Settings.String
+ | L'.TFfi ("Basis", "char") => Settings.Char
+ | L'.TFfi ("Basis", "bool") => Settings.Bool
+ | L'.TFfi ("Basis", "time") => Settings.Time
+ | L'.TFfi ("Basis", "blob") => Settings.Blob
+ | L'.TFfi ("Basis", "channel") => Settings.Channel
+ | L'.TFfi ("Basis", "client") => Settings.Client
+ | _ => raise Fail "Monoize/sql_option_prim: invalid SQL type"
in
((L'.EAbs ("f",
(L'.TFun (t, s), loc),
@@ -2223,7 +2236,7 @@ fun monoExp (env, st, fm) (all as (e, loc)) =
s,
(L'.ECase ((L'.ERel 0, loc),
[((L'.PNone t, loc),
- str "NULL"),
+ str (#p_cast (Settings.currentDbms ()) ("NULL", toSqlType t))),
((L'.PSome (t, (L'.PVar ("y", t), loc)), loc),
(L'.EApp ((L'.ERel 2, loc), (L'.ERel 0, loc)), loc))],
{disc = (L'.TOption t, loc),