ziv@2275: table tab : {Id : int, Val : int, Foo : int} PRIMARY KEY Id
ziv@2203:
ziv@2213: fun cache id =
ziv@2295: res <- oneOrNoRows (SELECT A.Val FROM (tab AS A JOIN tab AS B ON A.Id = B.Id)
ziv@2295: WHERE B.Id = {[id]});
ziv@2204: return
ziv@2278: cache
ziv@2276: {case res of
ziv@2276: None => ?
ziv@2295: | Some row => {[row.A.Val]}}
ziv@2276:
ziv@2276:
ziv@2294: (* fun cacheAlt id = *)
ziv@2294: (* res <- oneOrNoRows (SELECT Q.Id *)
ziv@2294: (* FROM (SELECT Tab.Id AS Id FROM tab WHERE Tab.Id = {[id]}) *)
ziv@2294: (* AS Q); *)
ziv@2294: (* return *)
ziv@2294: (* cacheAlt *)
ziv@2294: (* {case res of *)
ziv@2294: (* None => ? *)
ziv@2294: (* | Some row => {[row.Q.Id]}} *)
ziv@2294: (* *)
ziv@2276:
ziv@2294: (* fun sillyRecursive {Id = id : int, FooBar = fooBar} = *)
ziv@2294: (* if fooBar <= 0 *)
ziv@2294: (* then 0 *)
ziv@2294: (* else 1 + sillyRecursive {Id = id, FooBar = fooBar - 1} *)
ziv@2294:
ziv@2294: (* fun cacheR (r : {Id : int, FooBar : int}) = *)
ziv@2294: (* res <- oneOrNoRows (SELECT tab.Val *)
ziv@2294: (* FROM tab *)
ziv@2294: (* WHERE tab.Id = {[r.Id]}); *)
ziv@2294: (* return *)
ziv@2294: (* cacheR {[r.FooBar]} *)
ziv@2294: (* {case res of *)
ziv@2294: (* None => ? *)
ziv@2294: (* | Some row => {[row.Tab.Val]}} *)
ziv@2294: (* *)
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@2294: (* fun flash id = *)
ziv@2294: (* dml (UPDATE tab *)
ziv@2294: (* SET Foo = Val *)
ziv@2294: (* WHERE Id = {[id]} OR Id = {[id - 1]} OR Id = {[id + 1]}); *)
ziv@2294: (* return *)
ziv@2294: (* Maybe changed {[id]}? *)
ziv@2294: (* *)
ziv@2242:
ziv@2294: (* fun floosh id = *)
ziv@2294: (* dml (UPDATE tab *)
ziv@2294: (* SET Id = {[id + 1]} *)
ziv@2294: (* WHERE Id = {[id]} OR Id = {[id - 1]} OR Id = {[id + 1]}); *)
ziv@2294: (* return *)
ziv@2294: (* Shifted {[id]}! *)
ziv@2294: (* *)
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: (* *)