ziv@2275
|
1 table tab : {Id : int, Val : int, Foo : int} PRIMARY KEY Id
|
ziv@2203
|
2
|
ziv@2213
|
3 fun cache id =
|
ziv@2225
|
4 res <- oneOrNoRows (SELECT tab.Val
|
ziv@2225
|
5 FROM tab
|
ziv@2225
|
6 WHERE tab.Id = {[id]});
|
ziv@2204
|
7 return <xml><body>
|
ziv@2213
|
8 Reading {[id]}.
|
ziv@2204
|
9 {case res of
|
ziv@2213
|
10 None => <xml>?</xml>
|
ziv@2213
|
11 | Some row => <xml>{[row.Tab.Val]}</xml>}
|
ziv@2204
|
12 </body></xml>
|
ziv@2203
|
13
|
ziv@2273
|
14 (* fun cache2 id v = *)
|
ziv@2273
|
15 (* res <- oneOrNoRows (SELECT tab.Val *)
|
ziv@2273
|
16 (* FROM tab *)
|
ziv@2273
|
17 (* WHERE tab.Id = {[id]} AND tab.Val = {[v]}); *)
|
ziv@2273
|
18 (* return <xml><body> *)
|
ziv@2273
|
19 (* Reading {[id]}. *)
|
ziv@2273
|
20 (* {case res of *)
|
ziv@2273
|
21 (* None => <xml>Nope, that's not it.</xml> *)
|
ziv@2273
|
22 (* | Some _ => <xml>Hooray! You guessed it!</xml>} *)
|
ziv@2273
|
23 (* </body></xml> *)
|
ziv@2273
|
24
|
ziv@2275
|
25 (* fun cache2 id1 id2 = *)
|
ziv@2275
|
26 (* res1 <- oneOrNoRows (SELECT tab.Val *)
|
ziv@2275
|
27 (* FROM tab *)
|
ziv@2275
|
28 (* WHERE tab.Id = {[id1]}); *)
|
ziv@2275
|
29 (* res2 <- oneOrNoRows (SELECT tab.Val *)
|
ziv@2275
|
30 (* FROM tab *)
|
ziv@2275
|
31 (* WHERE tab.Id = {[id2]}); *)
|
ziv@2275
|
32 (* return <xml><body> *)
|
ziv@2275
|
33 (* Reading {[id1]} and {[id2]}. *)
|
ziv@2275
|
34 (* {case (res1, res2) of *)
|
ziv@2275
|
35 (* (Some _, Some _) => <xml>Both are there.</xml> *)
|
ziv@2275
|
36 (* | _ => <xml>One of them is missing.</xml>} *)
|
ziv@2275
|
37 (* </body></xml> *)
|
ziv@2269
|
38
|
ziv@2213
|
39 fun flush id =
|
ziv@2239
|
40 dml (UPDATE tab
|
ziv@2239
|
41 SET Val = Val * (Id + 2) / Val - 3
|
ziv@2239
|
42 WHERE Id = {[id]} OR Id = {[id - 1]} OR Id = {[id + 1]});
|
ziv@2204
|
43 return <xml><body>
|
ziv@2235
|
44 Changed {[id]}!
|
ziv@2204
|
45 </body></xml>
|
ziv@2234
|
46
|
ziv@2275
|
47 fun flash id =
|
ziv@2242
|
48 dml (UPDATE tab
|
ziv@2275
|
49 SET Foo = Val
|
ziv@2275
|
50 WHERE Id = {[id]} OR Id = {[id - 1]} OR Id = {[id + 1]});
|
ziv@2242
|
51 return <xml><body>
|
ziv@2275
|
52 Maybe changed {[id]}?
|
ziv@2242
|
53 </body></xml>
|
ziv@2242
|
54
|
ziv@2275
|
55 fun floosh id =
|
ziv@2275
|
56 dml (UPDATE tab
|
ziv@2275
|
57 SET Id = {[id + 1]}
|
ziv@2275
|
58 WHERE Id = {[id]});
|
ziv@2275
|
59 return <xml><body>
|
ziv@2275
|
60 Shifted {[id]}!
|
ziv@2275
|
61 </body></xml>
|
ziv@2275
|
62
|
ziv@2275
|
63 (* val flush17 = *)
|
ziv@2275
|
64 (* dml (UPDATE tab *)
|
ziv@2275
|
65 (* SET Val = Val * (Id + 2) / Val - 3 *)
|
ziv@2275
|
66 (* WHERE Id = 17); *)
|
ziv@2275
|
67 (* return <xml><body> *)
|
ziv@2275
|
68 (* Changed specifically 17! *)
|
ziv@2275
|
69 (* </body></xml> *)
|
ziv@2275
|
70
|
ziv@2235
|
71 (* fun flush id = *)
|
ziv@2235
|
72 (* res <- oneOrNoRows (SELECT tab.Val *)
|
ziv@2235
|
73 (* FROM tab *)
|
ziv@2235
|
74 (* WHERE tab.Id = {[id]}); *)
|
ziv@2235
|
75 (* (case res of *)
|
ziv@2235
|
76 (* None => dml (INSERT INTO tab (Id, Val) *)
|
ziv@2235
|
77 (* VALUES ({[id]}, 0)) *)
|
ziv@2235
|
78 (* | Some row => dml (UPDATE tab *)
|
ziv@2235
|
79 (* SET Val = {[row.Tab.Val + 1]} *)
|
ziv@2235
|
80 (* WHERE Id = {[id]} OR Id = {[id + 1]})); *)
|
ziv@2235
|
81 (* return <xml><body> *)
|
ziv@2235
|
82 (* {case res of *)
|
ziv@2235
|
83 (* None => <xml>Initialized {[id]}!</xml> *)
|
ziv@2235
|
84 (* | Some row => <xml>Incremented {[id]}!</xml>} *)
|
ziv@2235
|
85 (* </body></xml> *)
|