comparison demo/constraints.ur @ 773:74a090ff296e

constraints demo
author Adam Chlipala <adamc@hcoop.net>
date Sun, 03 May 2009 12:01:55 -0400
parents
children
comparison
equal deleted inserted replaced
772:8ed1261f838c 773:74a090ff296e
1 table t : { Id : int, Nam : string, Parent : option int }
2 PRIMARY KEY Id,
3 CONSTRAINT Nam UNIQUE Nam,
4 CONSTRAINT Id CHECK Id >= 0,
5 CONSTRAINT Parent FOREIGN KEY Parent REFERENCES t(Id)
6
7 fun main () =
8 list <- queryX (SELECT * FROM t)
9 (fn r => <xml><tr>
10 <td>{[r.T.Id]}</td>
11 <td>{[r.T.Nam]}</td>
12 <td>{case r.T.Parent of
13 None => <xml>NULL</xml>
14 | Some id => <xml>{[id]}</xml>}</td>
15 </tr></xml>);
16 return <xml><body>
17 <table>
18 <tr> <th>Id</th> <th>Name</th> <th>Parent</th> </tr>
19 {list}
20 </table>
21
22 <form>
23 <table>
24 <tr> <th>Id:</th> <td><textbox{#Id}/></td> </tr>
25 <tr> <th>Name:</th> <td><textbox{#Nam}/></td> </tr>
26 <tr> <th>Parent:</th> <td><textbox{#Parent}/></td> </tr>
27 <tr> <th/> <td><submit action={add}/></td> </tr>
28 </table>
29 </form>
30 </body></xml>
31
32 and add r =
33 dml (INSERT INTO t (Id, Nam, Parent)
34 VALUES ({[readError r.Id]}, {[r.Nam]},
35 {[case r.Parent of
36 "" => None
37 | s => Some (readError s)]}));
38 main ()