summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adamc@hcoop.net>2009-10-05 12:51:17 -0400
committerGravatar Adam Chlipala <adamc@hcoop.net>2009-10-05 12:51:17 -0400
commit280383cc8e3ac593d57ae26097a7b972edb2ea7a (patch)
treecff32a3f351a71dbf60b6e8109dde574f77bf89e
parent83ebcdd3e064431640437a9a073520e9b0ec8944 (diff)
Mangle local table names to avoid keyword clashes in SQL
-rw-r--r--src/monoize.sml16
-rw-r--r--tests/user.ur5
-rw-r--r--tests/user.urp5
-rw-r--r--tests/user.urs1
4 files changed, 21 insertions, 6 deletions
diff --git a/src/monoize.sml b/src/monoize.sml
index c3d91074..b80b4a65 100644
--- a/src/monoize.sml
+++ b/src/monoize.sml
@@ -1636,7 +1636,7 @@ fun monoExp (env, st, fm) (all as (e, loc)) =
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 @@ fun monoExp (env, st, fm) (all as (e, loc)) =
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 @@ fun monoExp (env, st, fm) (all as (e, loc)) =
@ 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 @@ fun monoExp (env, st, fm) (all as (e, loc)) =
strcatComma (map (fn (x, xts) =>
strcatComma
(map (fn (x', _) =>
- sc (x ^ ".uw_" ^ x'))
+ sc ("T_" ^ x
+ ^ ".uw_"
+ ^ x'))
xts)) grouped)
],
@@ -1968,7 +1972,7 @@ fun monoExp (env, st, fm) (all as (e, loc)) =
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 @@ fun monoExp (env, st, fm) (all as (e, loc)) =
_), _),
_), _),
(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 (
diff --git a/tests/user.ur b/tests/user.ur
new file mode 100644
index 00000000..c36fe407
--- /dev/null
+++ b/tests/user.ur
@@ -0,0 +1,5 @@
+table user : {A : int}
+
+fun main () =
+ r <- oneRow (SELECT COUNT( * ) AS N FROM user);
+ return <xml>{[r.N]}</xml>
diff --git a/tests/user.urp b/tests/user.urp
new file mode 100644
index 00000000..bbbc4351
--- /dev/null
+++ b/tests/user.urp
@@ -0,0 +1,5 @@
+debug
+database dbname=udb
+sql user.sql
+
+user
diff --git a/tests/user.urs b/tests/user.urs
new file mode 100644
index 00000000..6ac44e0b
--- /dev/null
+++ b/tests/user.urs
@@ -0,0 +1 @@
+val main : unit -> transaction page