changeset 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 28bf725de7f3
children 6dd122f10c0c
files src/monoize.sml tests/user.ur tests/user.urp tests/user.urs
diffstat 4 files changed, 21 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/monoize.sml	Sat Sep 26 12:57:01 2009 -0400
+++ b/src/monoize.sml	Mon Oct 05 12:51:17 2009 -0400
@@ -1636,7 +1636,7 @@
                                                     if #supportsUpdateAs (Settings.currentDbms ()) then
                                                         strcat [sc "UPDATE ",
                                                                 (L'.ERel 1, loc),
-                                                                sc " AS T SET ",
+                                                                sc " AS T_T SET ",
                                                                 strcatComma (map (fn (x, _) =>
                                                                                      strcat [sc ("uw_" ^ x
                                                                                                  ^ " = "),
@@ -1676,7 +1676,7 @@
                                      if #supportsDeleteAs (Settings.currentDbms ()) then
                                          strcat [sc "DELETE FROM ",
                                                  (L'.ERel 1, loc),
-                                                 sc " AS T WHERE ",
+                                                 sc " AS T_T WHERE ",
                                                  (L'.ERel 0, loc)]
                                      else
                                          strcat [sc "DELETE FROM ",
@@ -1823,7 +1823,9 @@
                                                         @ map (fn (x, xts) =>
                                                                   strcatComma
                                                                       (map (fn (x', _) =>
-                                                                               sc (x ^ ".uw_" ^ x'))
+                                                                               sc ("T_" ^ x
+										   ^ ".uw_"
+										   ^ x'))
                                                                            xts)) stables),
                                            sc " FROM ",
                                            gf "From",
@@ -1849,7 +1851,9 @@
                                                strcatComma (map (fn (x, xts) =>
                                                                     strcatComma
                                                                         (map (fn (x', _) =>
-                                                                                 sc (x ^ ".uw_" ^ x'))
+                                                                                 sc ("T_" ^ x
+										     ^ ".uw_"
+										     ^ x'))
                                                                              xts)) grouped)
                                                ],
 
@@ -1968,7 +1972,7 @@
             in
                 ((L'.EAbs ("tab", s, s,
                            strcat [(L'.ERel 0, loc),
-                                   (L'.EPrim (Prim.String (" AS " ^ name)), loc)]), loc),
+                                   (L'.EPrim (Prim.String (" AS T_" ^ name)), loc)]), loc),
                  fm)
             end
           | L.ECApp ((L.ECApp ((L.EFfi ("Basis", "sql_from_comma"), _), _), _), _) =>
@@ -2215,7 +2219,7 @@
                _), _),
               _), _),
              (L.CName tab, _)), _),
-            (L.CName field, _)) => ((L'.EPrim (Prim.String (tab ^ ".uw_" ^ lowercaseFirst field)), loc), fm)
+            (L.CName field, _)) => ((L'.EPrim (Prim.String ("T_" ^ tab ^ ".uw_" ^ lowercaseFirst field)), loc), fm)
 
           | L.ECApp (
             (L.ECApp (
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/user.ur	Mon Oct 05 12:51:17 2009 -0400
@@ -0,0 +1,5 @@
+table user : {A : int}
+
+fun main () =
+    r <- oneRow (SELECT COUNT( * ) AS N FROM user);
+    return <xml>{[r.N]}</xml>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/user.urp	Mon Oct 05 12:51:17 2009 -0400
@@ -0,0 +1,5 @@
+debug
+database dbname=udb
+sql user.sql
+
+user
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/user.urs	Mon Oct 05 12:51:17 2009 -0400
@@ -0,0 +1,1 @@
+val main : unit -> transaction page