diff src/monoize.sml @ 2160:72fe1cc704c5

Tag NULLs with their types in SQL, to help the DBMS do type inference
author Adam Chlipala <adam@chlipala.net>
date Sat, 04 Jul 2015 19:24:26 -0400
parents 5a010f408f36
children 849404a3af27 2b1af5dc6dee
line wrap: on
line diff
--- a/src/monoize.sml	Sat Jul 04 18:44:52 2015 -0400
+++ b/src/monoize.sml	Sat Jul 04 19:24:26 2015 -0400
@@ -2214,6 +2214,19 @@
             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 @@
                                      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),