changeset 337:18d5affa790d

Deletion for Crud
author Adam Chlipala <adamc@hcoop.net>
date Sat, 13 Sep 2008 20:15:30 -0400
parents 34847732cefc
children e976b187d73a
files src/cjr_print.sml tests/crud.ur
diffstat 2 files changed, 17 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/cjr_print.sml	Sat Sep 13 20:04:28 2008 -0400
+++ b/src/cjr_print.sml	Sat Sep 13 20:15:30 2008 -0400
@@ -898,7 +898,7 @@
         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 @@
 
              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
 
--- a/tests/crud.ur	Sat Sep 13 20:04:28 2008 -0400
+++ b/tests/crud.ur	Sat Sep 13 20:15:30 2008 -0400
@@ -14,6 +14,18 @@
 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 @@
                                                         <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>