comparison src/monoize.sml @ 986:d1dbb9a3c804

Mangle local table names to avoid keyword clashes in SQL
author Adam Chlipala <adamc@hcoop.net>
date Mon, 05 Oct 2009 12:51:17 -0400
parents 815afd323d86
children 10114d7b7477
comparison
equal deleted inserted replaced
985:28bf725de7f3 986:d1dbb9a3c804
1634 (L'.EAbs ("tab", s, (L'.TFun (s, s), loc), 1634 (L'.EAbs ("tab", s, (L'.TFun (s, s), loc),
1635 (L'.EAbs ("e", s, s, 1635 (L'.EAbs ("e", s, s,
1636 if #supportsUpdateAs (Settings.currentDbms ()) then 1636 if #supportsUpdateAs (Settings.currentDbms ()) then
1637 strcat [sc "UPDATE ", 1637 strcat [sc "UPDATE ",
1638 (L'.ERel 1, loc), 1638 (L'.ERel 1, loc),
1639 sc " AS T SET ", 1639 sc " AS T_T SET ",
1640 strcatComma (map (fn (x, _) => 1640 strcatComma (map (fn (x, _) =>
1641 strcat [sc ("uw_" ^ x 1641 strcat [sc ("uw_" ^ x
1642 ^ " = "), 1642 ^ " = "),
1643 (L'.EField 1643 (L'.EField
1644 ((L'.ERel 2, 1644 ((L'.ERel 2,
1674 ((L'.EAbs ("tab", s, (L'.TFun (s, s), loc), 1674 ((L'.EAbs ("tab", s, (L'.TFun (s, s), loc),
1675 (L'.EAbs ("e", s, s, 1675 (L'.EAbs ("e", s, s,
1676 if #supportsDeleteAs (Settings.currentDbms ()) then 1676 if #supportsDeleteAs (Settings.currentDbms ()) then
1677 strcat [sc "DELETE FROM ", 1677 strcat [sc "DELETE FROM ",
1678 (L'.ERel 1, loc), 1678 (L'.ERel 1, loc),
1679 sc " AS T WHERE ", 1679 sc " AS T_T WHERE ",
1680 (L'.ERel 0, loc)] 1680 (L'.ERel 0, loc)]
1681 else 1681 else
1682 strcat [sc "DELETE FROM ", 1682 strcat [sc "DELETE FROM ",
1683 (L'.ERel 1, loc), 1683 (L'.ERel 1, loc),
1684 sc " WHERE ", 1684 sc " WHERE ",
1821 sc (" AS _" ^ x) 1821 sc (" AS _" ^ x)
1822 ]) sexps 1822 ]) sexps
1823 @ map (fn (x, xts) => 1823 @ map (fn (x, xts) =>
1824 strcatComma 1824 strcatComma
1825 (map (fn (x', _) => 1825 (map (fn (x', _) =>
1826 sc (x ^ ".uw_" ^ x')) 1826 sc ("T_" ^ x
1827 ^ ".uw_"
1828 ^ x'))
1827 xts)) stables), 1829 xts)) stables),
1828 sc " FROM ", 1830 sc " FROM ",
1829 gf "From", 1831 gf "From",
1830 (L'.ECase (gf "Where", 1832 (L'.ECase (gf "Where",
1831 [((L'.PPrim (Prim.String "TRUE"), loc), 1833 [((L'.PPrim (Prim.String "TRUE"), loc),
1847 strcat [ 1849 strcat [
1848 sc " GROUP BY ", 1850 sc " GROUP BY ",
1849 strcatComma (map (fn (x, xts) => 1851 strcatComma (map (fn (x, xts) =>
1850 strcatComma 1852 strcatComma
1851 (map (fn (x', _) => 1853 (map (fn (x', _) =>
1852 sc (x ^ ".uw_" ^ x')) 1854 sc ("T_" ^ x
1855 ^ ".uw_"
1856 ^ x'))
1853 xts)) grouped) 1857 xts)) grouped)
1854 ], 1858 ],
1855 1859
1856 (L'.ECase (gf "Having", 1860 (L'.ECase (gf "Having",
1857 [((L'.PPrim (Prim.String "TRUE"), loc), 1861 [((L'.PPrim (Prim.String "TRUE"), loc),
1966 let 1970 let
1967 val s = (L'.TFfi ("Basis", "string"), loc) 1971 val s = (L'.TFfi ("Basis", "string"), loc)
1968 in 1972 in
1969 ((L'.EAbs ("tab", s, s, 1973 ((L'.EAbs ("tab", s, s,
1970 strcat [(L'.ERel 0, loc), 1974 strcat [(L'.ERel 0, loc),
1971 (L'.EPrim (Prim.String (" AS " ^ name)), loc)]), loc), 1975 (L'.EPrim (Prim.String (" AS T_" ^ name)), loc)]), loc),
1972 fm) 1976 fm)
1973 end 1977 end
1974 | L.ECApp ((L.ECApp ((L.EFfi ("Basis", "sql_from_comma"), _), _), _), _) => 1978 | L.ECApp ((L.ECApp ((L.EFfi ("Basis", "sql_from_comma"), _), _), _), _) =>
1975 let 1979 let
1976 val s = (L'.TFfi ("Basis", "string"), loc) 1980 val s = (L'.TFfi ("Basis", "string"), loc)
2213 _), _), 2217 _), _),
2214 _), _), 2218 _), _),
2215 _), _), 2219 _), _),
2216 _), _), 2220 _), _),
2217 (L.CName tab, _)), _), 2221 (L.CName tab, _)), _),
2218 (L.CName field, _)) => ((L'.EPrim (Prim.String (tab ^ ".uw_" ^ lowercaseFirst field)), loc), fm) 2222 (L.CName field, _)) => ((L'.EPrim (Prim.String ("T_" ^ tab ^ ".uw_" ^ lowercaseFirst field)), loc), fm)
2219 2223
2220 | L.ECApp ( 2224 | L.ECApp (
2221 (L.ECApp ( 2225 (L.ECApp (
2222 (L.ECApp ( 2226 (L.ECApp (
2223 (L.ECApp ( 2227 (L.ECApp (