summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adam@chlipala.net>2018-12-14 12:33:29 -0500
committerGravatar Adam Chlipala <adam@chlipala.net>2018-12-14 12:33:29 -0500
commit6d87f78102bba77bc090ca3fb105597d3ce3748f (patch)
tree3f65fb01ea19b745eb605c42265baa733c6ae75b
parent1781a9f989fb1d2839040300aba62c3398f6c0f9 (diff)
Proper ignoring of empty SQL updates
-rw-r--r--src/monoize.sml31
-rw-r--r--tests/emptyUpdate.ur6
-rw-r--r--tests/emptyUpdate.urp4
3 files changed, 38 insertions, 3 deletions
diff --git a/src/monoize.sml b/src/monoize.sml
index dfa88be3..48001a13 100644
--- a/src/monoize.sml
+++ b/src/monoize.sml
@@ -1540,17 +1540,31 @@ fun monoExp (env, st, fm) (all as (e, loc)) =
| L.EFfiApp ("Basis", "dml", [(e, _)]) =>
let
+ val string = (L'.TFfi ("Basis", "string"), loc)
val (e, fm) = monoExp (env, st, fm) e
in
- ((L'.EDml (e, L'.Error), loc),
+ ((L'.ECase (e,
+ [((L'.PPrim (Prim.String (Prim.Normal, "")), loc),
+ (L'.ERecord [], loc)),
+ ((L'.PVar ("cmd", string), loc),
+ (L'.EDml ((L'.ERel 0, loc), L'.Error), loc))],
+ {disc = string,
+ result = (L'.TRecord [], loc)}), loc),
fm)
end
| L.EFfiApp ("Basis", "tryDml", [(e, _)]) =>
let
+ val string = (L'.TFfi ("Basis", "string"), loc)
val (e, fm) = monoExp (env, st, fm) e
in
- ((L'.EDml (e, L'.None), loc),
+ ((L'.ECase (e,
+ [((L'.PPrim (Prim.String (Prim.Normal, "")), loc),
+ (L'.ERecord [], loc)),
+ ((L'.PVar ("cmd", string), loc),
+ (L'.EDml ((L'.ERel 0, loc), L'.None), loc))],
+ {disc = string,
+ result = (L'.TRecord [], loc)}), loc),
fm)
end
@@ -1579,7 +1593,18 @@ fun monoExp (env, st, fm) (all as (e, loc)) =
| L.ECApp ((L.ECApp ((L.ECApp ((L.EFfi ("Basis", "update"), _), _), _), _), _), changed) =>
(case monoType env (L.TRecord changed, loc) of
- (L'.TRecord changed, _) =>
+ (L'.TRecord [], _) =>
+ let
+ val s = (L'.TFfi ("Basis", "string"), loc)
+ val rt = (L'.TRecord [], loc)
+ in
+ ((L'.EAbs ("fs", rt, (L'.TFun (s, (L'.TFun (s, s), loc)), loc),
+ (L'.EAbs ("tab", s, (L'.TFun (s, s), loc),
+ (L'.EAbs ("e", s, s,
+ str ""), loc)), loc)), loc),
+ fm)
+ end
+ | (L'.TRecord changed, _) =>
let
val s = (L'.TFfi ("Basis", "string"), loc)
val changed = map (fn (x, _) => (x, s)) changed
diff --git a/tests/emptyUpdate.ur b/tests/emptyUpdate.ur
new file mode 100644
index 00000000..0402d78a
--- /dev/null
+++ b/tests/emptyUpdate.ur
@@ -0,0 +1,6 @@
+table a : { B : int }
+
+fun main () : transaction page =
+ dml (update [[]] {} a (WHERE TRUE));
+ return <xml></xml>
+
diff --git a/tests/emptyUpdate.urp b/tests/emptyUpdate.urp
new file mode 100644
index 00000000..42cc98e2
--- /dev/null
+++ b/tests/emptyUpdate.urp
@@ -0,0 +1,4 @@
+database dbname=test
+safeGet EmptyUpdate/main
+
+emptyUpdate