comparison 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
comparison
equal deleted inserted replaced
1206:772760df4c4c 1207:ae3036773768
6 type order = int 6 type order = int
7 table order : { Id : order, Fruit : fruit, Qty : int, Code : int } 7 table order : { Id : order, Fruit : fruit, Qty : int, Code : int }
8 PRIMARY KEY Id, 8 PRIMARY KEY Id,
9 CONSTRAINT Fruit FOREIGN KEY Fruit REFERENCES fruit(Id) 9 CONSTRAINT Fruit FOREIGN KEY Fruit REFERENCES fruit(Id)
10 10
11 policy query_policy (SELECT fruit.Id, fruit.Nam, fruit.Weight 11 (* Everyone may knows IDs and names. *)
12 policy query_policy (SELECT fruit.Id, fruit.Nam
12 FROM fruit) 13 FROM fruit)
14
15 (* The weight is sensitive information; you must know the secret. *)
16 policy query_policy (SELECT fruit.Weight
17 FROM fruit
18 WHERE known(fruit.Secret))
19
13 policy query_policy (SELECT order.Id, order.Fruit, order.Qty 20 policy query_policy (SELECT order.Id, order.Fruit, order.Qty
14 FROM order, fruit 21 FROM order, fruit
15 WHERE order.Fruit = fruit.Id 22 WHERE order.Fruit = fruit.Id
16 AND order.Qty = 13) 23 AND order.Qty = 13)
24
25 fun fname r =
26 x <- queryX (SELECT fruit.Weight
27 FROM fruit
28 WHERE fruit.Nam = {[r.Nam]}
29 AND fruit.Secret = {[r.Secret]})
30 (fn r => <xml>Weight is {[r.Fruit.Weight]}</xml>);
31
32 return <xml><body>
33 {x}
34 </body></xml>
17 35
18 fun main () = 36 fun main () =
19 x1 <- queryX (SELECT fruit.Id, fruit.Nam 37 x1 <- queryX (SELECT fruit.Id, fruit.Nam
20 FROM fruit) 38 FROM fruit)
21 (fn x => <xml><li>{[x.Fruit.Id]}: {[x.Fruit.Nam]}</li></xml>); 39 (fn x => <xml><li>{[x.Fruit.Id]}: {[x.Fruit.Nam]}</li></xml>);
27 (fn x => <xml><li>{[x.Fruit.Nam]}: {[x.Order.Qty]}</li></xml>); 45 (fn x => <xml><li>{[x.Fruit.Nam]}: {[x.Order.Qty]}</li></xml>);
28 46
29 return <xml><body> 47 return <xml><body>
30 <ul>{x1}</ul> 48 <ul>{x1}</ul>
31 <ul>{x2}</ul> 49 <ul>{x2}</ul>
50
51 <form>
52 Fruit name: <textbox{#Nam}/><br/>
53 Secret: <textbox{#Secret}/><br/>
54 <submit action={fname}/>
55 </form>
32 </body></xml> 56 </body></xml>