summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adamc@hcoop.net>2008-09-13 20:15:30 -0400
committerGravatar Adam Chlipala <adamc@hcoop.net>2008-09-13 20:15:30 -0400
commit0faed8b64498534297bd797108b659802815aefc (patch)
tree30fae6d25a85af9fcf9b87c425788c9e042c46c2
parentb145e03e5e25cfd59f544312efe3ea93e265a8ce (diff)
Deletion for Crud
-rw-r--r--src/cjr_print.sml6
-rw-r--r--tests/crud.ur13
2 files changed, 17 insertions, 2 deletions
diff --git a/src/cjr_print.sml b/src/cjr_print.sml
index b90854a1..f784f3d4 100644
--- a/src/cjr_print.sml
+++ b/src/cjr_print.sml
@@ -898,7 +898,7 @@ fun p_exp' par env (e, loc) =
end
| EDml {dml, prepared} =>
- box [string "({",
+ box [string "(uw_begin_region(ctx), ({",
newline,
string "PGconn *conn = uw_get_db(ctx);",
newline,
@@ -970,9 +970,11 @@ fun p_exp' par env (e, loc) =
string "PQclear(res);",
newline,
+ string "uw_end_region(ctx);",
+ newline,
string "uw_unit_v;",
newline,
- string "})"]
+ string "}))"]
and p_exp env = p_exp' false env
diff --git a/tests/crud.ur b/tests/crud.ur
index c596eaad..75136226 100644
--- a/tests/crud.ur
+++ b/tests/crud.ur
@@ -14,6 +14,18 @@ end) = struct
open constraints M
val tab = M.tab
+fun delete (id : int) =
+ () <- dml (DELETE FROM tab WHERE Id = {id});
+ return <html><body>
+ The deed is done.
+ </body></html>
+
+fun confirm (id : int) = return <html><body>
+ <p>Are you sure you want to delete ID #{txt _ id}?</p>
+
+ <p><a link={delete id}>I was born sure!</a></p>
+</body></html>
+
fun main () : transaction page =
rows <- queryX (SELECT * FROM tab AS T)
(fn (fs : {T : $([Id = int] ++ M.cols)}) => <body>
@@ -26,6 +38,7 @@ fun main () : transaction page =
<td>{col.Show v}</td>
</tr>)
[M.cols] (fs.T -- #Id) M.cols}
+ <td><a link={confirm fs.T.Id}>[Delete]</a></td>
</tr>
</body>);
return <html><head>