# HG changeset patch # User Adam Chlipala # Date 1446415336 18000 # Node ID 849404a3af27589fe8cc31f459ec02a294cf40fb # Parent 22117edf8fd3cc3767a3574e4a58f23914493e3e Change behavior of SQL equality to do the intuitive thing for nullable types diff -r 22117edf8fd3 -r 849404a3af27 lib/ur/basis.urs --- a/lib/ur/basis.urs Sun Nov 01 16:33:14 2015 -0500 +++ b/lib/ur/basis.urs Sun Nov 01 17:02:16 2015 -0500 @@ -554,6 +554,9 @@ val sql_mod : sql_binary int int int val sql_eq : t ::: Type -> sql_binary t t bool +(* Note that the semantics of this operator on nullable types are different than for standard SQL! + * Instead, we do it the sane way, where [NULL = NULL]. *) + val sql_ne : t ::: Type -> sql_binary t t bool val sql_lt : t ::: Type -> sql_binary t t bool val sql_le : t ::: Type -> sql_binary t t bool diff -r 22117edf8fd3 -r 849404a3af27 src/monoize.sml --- a/src/monoize.sml Sun Nov 01 16:33:14 2015 -0500 +++ b/src/monoize.sml Sun Nov 01 17:02:16 2015 -0500 @@ -2592,22 +2592,45 @@ _), _), _), _), _), _), - _), _), + arg1), _), _), _), _) => let val s = (L'.TFfi ("Basis", "string"), loc) + + val default = strcat [str "(", + (L'.ERel 1, loc), + str " ", + (L'.ERel 2, loc), + str " ", + (L'.ERel 0, loc), + str ")"] + + val body = case #1 arg1 of + L.CApp ((L.CFfi ("Basis", "option"), _), _) => + (L'.ECase ((L'.ERel 2, loc), + [((L'.PPrim (Prim.String (Prim.Normal, "=")), loc), + strcat [str "((", + (L'.ERel 1, loc), + str " ", + (L'.ERel 2, loc), + str " ", + (L'.ERel 0, loc), + str ") OR ((", + (L'.ERel 1, loc), + str ") IS NULL AND (", + (L'.ERel 0, loc), + str ") IS NULL))"]), + ((L'.PWild, loc), + default)], + {disc = s, + result = s}), loc) + | _ => default in ((L'.EAbs ("c", s, (L'.TFun (s, (L'.TFun (s, s), loc)), loc), (L'.EAbs ("e1", s, (L'.TFun (s, s), loc), (L'.EAbs ("e2", s, s, - strcat [str "(", - (L'.ERel 1, loc), - str " ", - (L'.ERel 2, loc), - str " ", - (L'.ERel 0, loc), - str ")"]), loc)), loc)), loc), + body), loc)), loc)), loc), fm) end | L.EFfi ("Basis", "sql_and") => (str "AND", fm)