comparison caching-tests/test.ur @ 2235:0aae15c2a05a

Refactored a lot and fixed an and/or swap, but still not good on current test.
author Ziv Scully <ziv@mit.edu>
date Mon, 29 Jun 2015 01:33:47 -0700
parents 2f7ed04332a0
children fab8c1f131a5
comparison
equal deleted inserted replaced
2234:2f7ed04332a0 2235:0aae15c2a05a
9 {case res of 9 {case res of
10 None => <xml>?</xml> 10 None => <xml>?</xml>
11 | Some row => <xml>{[row.Tab.Val]}</xml>} 11 | Some row => <xml>{[row.Tab.Val]}</xml>}
12 </body></xml> 12 </body></xml>
13 13
14
14 fun flush id = 15 fun flush id =
15 res <- oneOrNoRows (SELECT tab.Val 16 dml (UPDATE tab
16 FROM tab 17 SET Val = 42
17 WHERE tab.Id = {[id]}); 18 WHERE Id = {[id]} OR Id = {[id + 1]});
18 (case res of
19 None => return () (* dml (INSERT INTO tab (Id, Val) *)
20 (* VALUES ({[id]}, 0)) *)
21 | Some row => dml (UPDATE tab
22 SET Val = {[row.Tab.Val + 1]}
23 WHERE Id = {[id + 1]} OR Id = {[id]} (* OR Id = {[id - 1]} *)));
24 return <xml><body> 19 return <xml><body>
25 {case res of 20 Changed {[id]}!
26 None => <xml>Initialized {[id]}!</xml>
27 | Some row => <xml>Incremented {[id]}!</xml>}
28 </body></xml> 21 </body></xml>
29 22
30 (* task periodic 5 = *) 23 (* fun flush id = *)
31 (* fn () => *) 24 (* res <- oneOrNoRows (SELECT tab.Val *)
32 (* t <- now; *) 25 (* FROM tab *)
33 (* let *) 26 (* WHERE tab.Id = {[id]}); *)
34 (* val n = toSeconds t % 2 *) 27 (* (case res of *)
35 (* in *) 28 (* None => dml (INSERT INTO tab (Id, Val) *)
36 (* dml (UPDATE tab *) 29 (* VALUES ({[id]}, 0)) *)
37 (* SET Val = 9001 *) 30 (* | Some row => dml (UPDATE tab *)
38 (* WHERE Id = {[n]} OR Id = {[n+1]}) *) 31 (* SET Val = {[row.Tab.Val + 1]} *)
39 (* end *) 32 (* WHERE Id = {[id]} OR Id = {[id + 1]})); *)
33 (* return <xml><body> *)
34 (* {case res of *)
35 (* None => <xml>Initialized {[id]}!</xml> *)
36 (* | Some row => <xml>Incremented {[id]}!</xml>} *)
37 (* </body></xml> *)