ziv@2213: table tab : {Id : int, Val : int} PRIMARY KEY Id
ziv@2203:
ziv@2213: fun cache id =
ziv@2225: res <- oneOrNoRows (SELECT tab.Val
ziv@2225: FROM tab
ziv@2225: WHERE tab.Id = {[id]});
ziv@2204: return
ziv@2213: Reading {[id]}.
ziv@2204: {case res of
ziv@2213: None => ?
ziv@2213: | Some row => {[row.Tab.Val]}}
ziv@2204:
ziv@2203:
ziv@2269: fun cache2 id v =
ziv@2269: res <- oneOrNoRows (SELECT tab.Val
ziv@2269: FROM tab
ziv@2269: WHERE tab.Id = {[id]} AND tab.Val = {[v]});
ziv@2269: return
ziv@2269: Reading {[id]}.
ziv@2269: {case res of
ziv@2269: None => Nope, that's not it.
ziv@2269: | Some _ => Hooray! You guessed it!}
ziv@2269:
ziv@2269:
ziv@2213: fun flush id =
ziv@2239: dml (UPDATE tab
ziv@2239: SET Val = Val * (Id + 2) / Val - 3
ziv@2239: WHERE Id = {[id]} OR Id = {[id - 1]} OR Id = {[id + 1]});
ziv@2204: return
ziv@2235: Changed {[id]}!
ziv@2204:
ziv@2234:
ziv@2242: val flush17 =
ziv@2242: dml (UPDATE tab
ziv@2242: SET Val = Val * (Id + 2) / Val - 3
ziv@2242: WHERE Id = 17);
ziv@2242: return
ziv@2242: Changed specifically 17!
ziv@2242:
ziv@2242:
ziv@2235: (* fun flush id = *)
ziv@2235: (* res <- oneOrNoRows (SELECT tab.Val *)
ziv@2235: (* FROM tab *)
ziv@2235: (* WHERE tab.Id = {[id]}); *)
ziv@2235: (* (case res of *)
ziv@2235: (* None => dml (INSERT INTO tab (Id, Val) *)
ziv@2235: (* VALUES ({[id]}, 0)) *)
ziv@2235: (* | Some row => dml (UPDATE tab *)
ziv@2235: (* SET Val = {[row.Tab.Val + 1]} *)
ziv@2235: (* WHERE Id = {[id]} OR Id = {[id + 1]})); *)
ziv@2235: (* return *)
ziv@2235: (* {case res of *)
ziv@2235: (* None => Initialized {[id]}! *)
ziv@2235: (* | Some row => Incremented {[id]}!} *)
ziv@2235: (* *)