annotate demo/refFun.ur @ 475:9babc5d2ec5a

Fix parsing of last input header
author Adam Chlipala <adamc@hcoop.net>
date Sat, 08 Nov 2008 10:58:59 -0500
parents 20fab0e96217
children 7ef4b2911b09
rev   line source
adamc@419 1 functor Make(M : sig
adamc@419 2 type data
adamc@419 3 val inj : sql_injectable data
adamc@419 4 end) = struct
adamc@419 5
adamc@419 6 type ref = int
adamc@419 7
adamc@419 8 sequence s
adamc@419 9 table t : { Id : int, Data : M.data }
adamc@419 10
adamc@419 11 fun new d =
adamc@419 12 id <- nextval s;
adamc@471 13 dml (INSERT INTO t (Id, Data) VALUES ({[id]}, {[d]}));
adamc@419 14 return id
adamc@419 15
adamc@419 16 fun read r =
adamc@471 17 o <- oneOrNoRows (SELECT t.Data FROM t WHERE t.Id = {[r]});
adamc@419 18 return (case o of
adamc@419 19 None => error <xml>You already deleted that ref!</xml>
adamc@419 20 | Some r => r.T.Data)
adamc@419 21
adamc@419 22 fun write r d =
adamc@471 23 dml (UPDATE t SET Data = {[d]} WHERE Id = {[r]})
adamc@419 24
adamc@419 25 fun delete r =
adamc@471 26 dml (DELETE FROM t WHERE Id = {[r]})
adamc@420 27
adamc@419 28 end