ziv@2275: table tab : {Id : int, Val : int, Foo : 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@2278: cache
ziv@2276: {case res of
ziv@2276: None => ?
ziv@2276: | Some row => {[row.Tab.Val]}}
ziv@2276:
ziv@2276:
ziv@2278: fun sillyRecursive {Id = id : int, FooBar = fooBar} =
ziv@2278: if fooBar <= 0
ziv@2278: then 0
ziv@2278: else 1 + sillyRecursive {Id = id, FooBar = fooBar - 1}
ziv@2276:
ziv@2276: fun cacheR (r : {Id : int, FooBar : int}) =
ziv@2276: res <- oneOrNoRows (SELECT tab.Val
ziv@2276: FROM tab
ziv@2276: WHERE tab.Id = {[r.Id]});
ziv@2276: return
ziv@2278: cacheR {[r.FooBar]}
ziv@2204: {case res of
ziv@2213: None => ?
ziv@2213: | Some row => {[row.Tab.Val]}}
ziv@2204:
ziv@2203:
ziv@2273: (* fun cache2 id v = *)
ziv@2273: (* res <- oneOrNoRows (SELECT tab.Val *)
ziv@2273: (* FROM tab *)
ziv@2273: (* WHERE tab.Id = {[id]} AND tab.Val = {[v]}); *)
ziv@2273: (* return *)
ziv@2273: (* Reading {[id]}. *)
ziv@2273: (* {case res of *)
ziv@2273: (* None => Nope, that's not it. *)
ziv@2273: (* | Some _ => Hooray! You guessed it!} *)
ziv@2273: (* *)
ziv@2273:
ziv@2275: (* fun cache2 id1 id2 = *)
ziv@2275: (* res1 <- oneOrNoRows (SELECT tab.Val *)
ziv@2275: (* FROM tab *)
ziv@2275: (* WHERE tab.Id = {[id1]}); *)
ziv@2275: (* res2 <- oneOrNoRows (SELECT tab.Val *)
ziv@2275: (* FROM tab *)
ziv@2275: (* WHERE tab.Id = {[id2]}); *)
ziv@2275: (* return *)
ziv@2275: (* Reading {[id1]} and {[id2]}. *)
ziv@2275: (* {case (res1, res2) of *)
ziv@2275: (* (Some _, Some _) => Both are there. *)
ziv@2275: (* | _ => One of them is missing.} *)
ziv@2275: (* *)
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@2275: fun flash id =
ziv@2242: dml (UPDATE tab
ziv@2275: SET Foo = Val
ziv@2275: WHERE Id = {[id]} OR Id = {[id - 1]} OR Id = {[id + 1]});
ziv@2242: return
ziv@2275: Maybe changed {[id]}?
ziv@2242:
ziv@2242:
ziv@2275: fun floosh id =
ziv@2275: dml (UPDATE tab
ziv@2275: SET Id = {[id + 1]}
ziv@2275: WHERE Id = {[id]});
ziv@2275: return
ziv@2275: Shifted {[id]}!
ziv@2275:
ziv@2275:
ziv@2275: (* val flush17 = *)
ziv@2275: (* dml (UPDATE tab *)
ziv@2275: (* SET Val = Val * (Id + 2) / Val - 3 *)
ziv@2275: (* WHERE Id = 17); *)
ziv@2275: (* return *)
ziv@2275: (* Changed specifically 17! *)
ziv@2275: (* *)
ziv@2275:
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: (* *)