annotate tests/policy.ur @ 1207:ae3036773768

Introduced the known() predicate
author Adam Chlipala <adamc@hcoop.net>
date Tue, 06 Apr 2010 09:51:36 -0400
parents 772760df4c4c
children 775357041e48
rev   line source
adamc@1204 1 type fruit = int
adamc@1204 2 table fruit : { Id : fruit, Nam : string, Weight : float, Secret : string }
adamc@1204 3 PRIMARY KEY Id,
adamc@1204 4 CONSTRAINT Nam UNIQUE Nam
adamc@1204 5
adamc@1204 6 type order = int
adamc@1204 7 table order : { Id : order, Fruit : fruit, Qty : int, Code : int }
adamc@1204 8 PRIMARY KEY Id,
adamc@1204 9 CONSTRAINT Fruit FOREIGN KEY Fruit REFERENCES fruit(Id)
adamc@1199 10
adamc@1207 11 (* Everyone may knows IDs and names. *)
adamc@1207 12 policy query_policy (SELECT fruit.Id, fruit.Nam
adamc@1205 13 FROM fruit)
adamc@1207 14
adamc@1207 15 (* The weight is sensitive information; you must know the secret. *)
adamc@1207 16 policy query_policy (SELECT fruit.Weight
adamc@1207 17 FROM fruit
adamc@1207 18 WHERE known(fruit.Secret))
adamc@1207 19
adamc@1205 20 policy query_policy (SELECT order.Id, order.Fruit, order.Qty
adamc@1205 21 FROM order, fruit
adamc@1206 22 WHERE order.Fruit = fruit.Id
adamc@1206 23 AND order.Qty = 13)
adamc@1200 24
adamc@1207 25 fun fname r =
adamc@1207 26 x <- queryX (SELECT fruit.Weight
adamc@1207 27 FROM fruit
adamc@1207 28 WHERE fruit.Nam = {[r.Nam]}
adamc@1207 29 AND fruit.Secret = {[r.Secret]})
adamc@1207 30 (fn r => <xml>Weight is {[r.Fruit.Weight]}</xml>);
adamc@1207 31
adamc@1207 32 return <xml><body>
adamc@1207 33 {x}
adamc@1207 34 </body></xml>
adamc@1207 35
adamc@1200 36 fun main () =
adamc@1204 37 x1 <- queryX (SELECT fruit.Id, fruit.Nam
adamc@1204 38 FROM fruit)
adamc@1204 39 (fn x => <xml><li>{[x.Fruit.Id]}: {[x.Fruit.Nam]}</li></xml>);
adamc@1204 40
adamc@1204 41 x2 <- queryX (SELECT fruit.Nam, order.Qty
adamc@1204 42 FROM fruit, order
adamc@1206 43 WHERE fruit.Id = order.Fruit
adamc@1206 44 AND order.Qty = 13)
adamc@1204 45 (fn x => <xml><li>{[x.Fruit.Nam]}: {[x.Order.Qty]}</li></xml>);
adamc@1200 46
adamc@1200 47 return <xml><body>
adamc@1204 48 <ul>{x1}</ul>
adamc@1204 49 <ul>{x2}</ul>
adamc@1207 50
adamc@1207 51 <form>
adamc@1207 52 Fruit name: <textbox{#Nam}/><br/>
adamc@1207 53 Secret: <textbox{#Secret}/><br/>
adamc@1207 54 <submit action={fname}/>
adamc@1207 55 </form>
adamc@1200 56 </body></xml>