adamc@1204: type fruit = int
adamc@1204: table fruit : { Id : fruit, Nam : string, Weight : float, Secret : string }
adamc@1204: PRIMARY KEY Id,
adamc@1204: CONSTRAINT Nam UNIQUE Nam
adamc@1204:
adamc@1204: type order = int
adamc@1204: table order : { Id : order, Fruit : fruit, Qty : int, Code : int }
adamc@1204: PRIMARY KEY Id,
adamc@1204: CONSTRAINT Fruit FOREIGN KEY Fruit REFERENCES fruit(Id)
adamc@1199:
adamc@1207: (* Everyone may knows IDs and names. *)
adamc@1214: policy sendClient (SELECT fruit.Id, fruit.Nam
adamc@1214: FROM fruit)
adamc@1207:
adamc@1207: (* The weight is sensitive information; you must know the secret. *)
adamc@1214: policy sendClient (SELECT fruit.Weight, fruit.Secret
adamc@1214: FROM fruit
adamc@1214: WHERE known(fruit.Secret))
adamc@1207:
adamc@1214: policy sendClient (SELECT order.Id, order.Fruit, order.Qty
adamc@1214: FROM order, fruit
adamc@1214: WHERE order.Fruit = fruit.Id
adamc@1214: AND order.Qty = 13)
adamc@1200:
adamc@1207: fun fname r =
adamc@1207: x <- queryX (SELECT fruit.Weight
adamc@1207: FROM fruit
adamc@1207: WHERE fruit.Nam = {[r.Nam]}
adamc@1210: AND fruit.Secret = {[r.Secret]}
adamc@1210: AND fruit.Weight <> 3.14
adamc@1210: AND fruit.Weight < 100.0
adamc@1210: AND fruit.Weight <= 200.1
adamc@1210: AND fruit.Weight > 1.23
adamc@1210: AND fruit.Weight >= 1.24)
adamc@1207: (fn r => Weight is {[r.Fruit.Weight]});
adamc@1207:
adamc@1207: return
adamc@1207: {x}
adamc@1207:
adamc@1207:
adamc@1200: fun main () =
adamc@1204: x1 <- queryX (SELECT fruit.Id, fruit.Nam
adamc@1209: FROM fruit
adamc@1210: WHERE fruit.Nam = "apple")
adamc@1204: (fn x => {[x.Fruit.Id]}: {[x.Fruit.Nam]});
adamc@1204:
adamc@1204: x2 <- queryX (SELECT fruit.Nam, order.Qty
adamc@1204: FROM fruit, order
adamc@1206: WHERE fruit.Id = order.Fruit
adamc@1206: AND order.Qty = 13)
adamc@1204: (fn x => {[x.Fruit.Nam]}: {[x.Order.Qty]});
adamc@1200:
adamc@1200: return
adamc@1204:
adamc@1210:
adamc@1204:
adamc@1207:
adamc@1207:
adamc@1200: