Mercurial > urweb
comparison 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 |
comparison
equal
deleted
inserted
replaced
2159:9029e0e2c67c | 2160:72fe1cc704c5 |
---|---|
2212 end | 2212 end |
2213 | L.ECApp ((L.EFfi ("Basis", "sql_option_prim"), _), t) => | 2213 | L.ECApp ((L.EFfi ("Basis", "sql_option_prim"), _), t) => |
2214 let | 2214 let |
2215 val t = monoType env t | 2215 val t = monoType env t |
2216 val s = (L'.TFfi ("Basis", "string"), loc) | 2216 val s = (L'.TFfi ("Basis", "string"), loc) |
2217 | |
2218 fun toSqlType (t : L'.typ) = | |
2219 case #1 t of | |
2220 L'.TFfi ("Basis", "int") => Settings.Int | |
2221 | L'.TFfi ("Basis", "float") => Settings.Float | |
2222 | L'.TFfi ("Basis", "string") => Settings.String | |
2223 | L'.TFfi ("Basis", "char") => Settings.Char | |
2224 | L'.TFfi ("Basis", "bool") => Settings.Bool | |
2225 | L'.TFfi ("Basis", "time") => Settings.Time | |
2226 | L'.TFfi ("Basis", "blob") => Settings.Blob | |
2227 | L'.TFfi ("Basis", "channel") => Settings.Channel | |
2228 | L'.TFfi ("Basis", "client") => Settings.Client | |
2229 | _ => raise Fail "Monoize/sql_option_prim: invalid SQL type" | |
2217 in | 2230 in |
2218 ((L'.EAbs ("f", | 2231 ((L'.EAbs ("f", |
2219 (L'.TFun (t, s), loc), | 2232 (L'.TFun (t, s), loc), |
2220 (L'.TFun ((L'.TOption t, loc), s), loc), | 2233 (L'.TFun ((L'.TOption t, loc), s), loc), |
2221 (L'.EAbs ("x", | 2234 (L'.EAbs ("x", |
2222 (L'.TOption t, loc), | 2235 (L'.TOption t, loc), |
2223 s, | 2236 s, |
2224 (L'.ECase ((L'.ERel 0, loc), | 2237 (L'.ECase ((L'.ERel 0, loc), |
2225 [((L'.PNone t, loc), | 2238 [((L'.PNone t, loc), |
2226 str "NULL"), | 2239 str (#p_cast (Settings.currentDbms ()) ("NULL", toSqlType t))), |
2227 ((L'.PSome (t, (L'.PVar ("y", t), loc)), loc), | 2240 ((L'.PSome (t, (L'.PVar ("y", t), loc)), loc), |
2228 (L'.EApp ((L'.ERel 2, loc), (L'.ERel 0, loc)), loc))], | 2241 (L'.EApp ((L'.ERel 2, loc), (L'.ERel 0, loc)), loc))], |
2229 {disc = (L'.TOption t, loc), | 2242 {disc = (L'.TOption t, loc), |
2230 result = s}), loc)), loc)), loc), | 2243 result = s}), loc)), loc)), loc), |
2231 fm) | 2244 fm) |