# HG changeset patch # User Adam Chlipala # Date 1436052266 14400 # Node ID 72fe1cc704c5c76f253593398aa64e230215c897 # Parent 9029e0e2c67c4d46b1faa012bda09c479facb463 Tag NULLs with their types in SQL, to help the DBMS do type inference diff -r 9029e0e2c67c -r 72fe1cc704c5 src/monoize.sml --- 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),