Mercurial > urweb
comparison demo/sql.ur @ 410:c5a3d223f157
Sql demo
author | Adam Chlipala <adamc@hcoop.net> |
---|---|
date | Tue, 21 Oct 2008 18:44:52 -0400 |
parents | |
children | c471345f5165 |
comparison
equal
deleted
inserted
replaced
409:81d9f42bb641 | 410:c5a3d223f157 |
---|---|
1 table t : { A : int, B : float, C : string, D : bool } | |
2 | |
3 fun list () = | |
4 rows <- queryX (SELECT * FROM t) | |
5 (fn row => <xml><tr> | |
6 <td>{[row.T.A]}</td> <td>{[row.T.B]}</td> <td>{[row.T.C]}</td> <td>{[row.T.D]}</td> | |
7 <td><a link={delete row.T.A}>[delete]</a></td> | |
8 </tr></xml>); | |
9 return <xml> | |
10 <table border=1> | |
11 <tr> <th>A</th> <th>B</th> <th>C</th> <th>D</th> </tr> | |
12 {rows} | |
13 </table> | |
14 | |
15 <br/><hr/><br/> | |
16 | |
17 <form> | |
18 <table> | |
19 <tr> <th>A:</th> <td><textbox{#A}/></td> </tr> | |
20 <tr> <th>B:</th> <td><textbox{#B}/></td> </tr> | |
21 <tr> <th>C:</th> <td><textbox{#C}/></td> </tr> | |
22 <tr> <th>D:</th> <td><checkbox{#D}/></td> </tr> | |
23 <tr> <th/> <td><submit action={add} value="Add Row"/></td> </tr> | |
24 </table> | |
25 </form> | |
26 </xml> | |
27 | |
28 and add r = | |
29 () <- dml (INSERT INTO t (A, B, C, D) | |
30 VALUES ({readError r.A}, {readError r.B}, {r.C}, {r.D})); | |
31 xml <- list (); | |
32 return <xml><body> | |
33 <p>Row added.</p> | |
34 | |
35 {xml} | |
36 </body></xml> | |
37 | |
38 and delete a = | |
39 () <- dml (DELETE FROM t | |
40 WHERE t.A = {a}); | |
41 xml <- list (); | |
42 return <xml><body> | |
43 <p>Row deleted.</p> | |
44 | |
45 {xml} | |
46 </body></xml> | |
47 | |
48 fun main () = | |
49 xml <- list (); | |
50 return <xml><body> | |
51 {xml} | |
52 </body></xml> |