Mercurial > urweb
annotate demo/constraints.ur @ 1656:3e7c7e200713
Fix handling of quotes in generating C literals
author | Adam Chlipala <adam@chlipala.net> |
---|---|
date | Mon, 02 Jan 2012 17:08:39 -0500 |
parents | 74a090ff296e |
children |
rev | line source |
---|---|
adamc@773 | 1 table t : { Id : int, Nam : string, Parent : option int } |
adamc@773 | 2 PRIMARY KEY Id, |
adamc@773 | 3 CONSTRAINT Nam UNIQUE Nam, |
adamc@773 | 4 CONSTRAINT Id CHECK Id >= 0, |
adamc@773 | 5 CONSTRAINT Parent FOREIGN KEY Parent REFERENCES t(Id) |
adamc@773 | 6 |
adamc@773 | 7 fun main () = |
adamc@773 | 8 list <- queryX (SELECT * FROM t) |
adamc@773 | 9 (fn r => <xml><tr> |
adamc@773 | 10 <td>{[r.T.Id]}</td> |
adamc@773 | 11 <td>{[r.T.Nam]}</td> |
adamc@773 | 12 <td>{case r.T.Parent of |
adamc@773 | 13 None => <xml>NULL</xml> |
adamc@773 | 14 | Some id => <xml>{[id]}</xml>}</td> |
adamc@773 | 15 </tr></xml>); |
adamc@773 | 16 return <xml><body> |
adamc@773 | 17 <table> |
adamc@773 | 18 <tr> <th>Id</th> <th>Name</th> <th>Parent</th> </tr> |
adamc@773 | 19 {list} |
adamc@773 | 20 </table> |
adamc@773 | 21 |
adamc@773 | 22 <form> |
adamc@773 | 23 <table> |
adamc@773 | 24 <tr> <th>Id:</th> <td><textbox{#Id}/></td> </tr> |
adamc@773 | 25 <tr> <th>Name:</th> <td><textbox{#Nam}/></td> </tr> |
adamc@773 | 26 <tr> <th>Parent:</th> <td><textbox{#Parent}/></td> </tr> |
adamc@773 | 27 <tr> <th/> <td><submit action={add}/></td> </tr> |
adamc@773 | 28 </table> |
adamc@773 | 29 </form> |
adamc@773 | 30 </body></xml> |
adamc@773 | 31 |
adamc@773 | 32 and add r = |
adamc@773 | 33 dml (INSERT INTO t (Id, Nam, Parent) |
adamc@773 | 34 VALUES ({[readError r.Id]}, {[r.Nam]}, |
adamc@773 | 35 {[case r.Parent of |
adamc@773 | 36 "" => None |
adamc@773 | 37 | s => Some (readError s)]})); |
adamc@773 | 38 main () |