comparison caching-tests/test.ur @ 2294:f8903af753ff

Support nested queries but disable UrFlow for now.
author Ziv Scully <ziv@mit.edu>
date Thu, 19 Nov 2015 01:59:00 -0500
parents b7615e0ac4b0
children e6c5bb62fef8
comparison
equal deleted inserted replaced
2293:8be54d7bd06e 2294:f8903af753ff
1 table tab : {Id : int, Val : int, Foo : int} PRIMARY KEY Id 1 table tab : {Id : int, Val : int, Foo : int} PRIMARY KEY Id
2 2
3 fun cache id = 3 fun cache id =
4 res <- oneOrNoRows (SELECT tab.Val 4 res <- oneOrNoRows (SELECT tab.Val FROM tab WHERE tab.Id = {[id]});
5 FROM tab
6 WHERE tab.Id = {[id]});
7 return <xml><body> 5 return <xml><body>
8 cache 6 cache
9 {case res of 7 {case res of
10 None => <xml>?</xml> 8 None => <xml>?</xml>
11 | Some row => <xml>{[row.Tab.Val]}</xml>} 9 | Some row => <xml>{[row.Tab.Val]}</xml>}
12 </body></xml> 10 </body></xml>
13 11
14 fun sillyRecursive {Id = id : int, FooBar = fooBar} = 12 (* fun cacheAlt id = *)
15 if fooBar <= 0 13 (* res <- oneOrNoRows (SELECT Q.Id *)
16 then 0 14 (* FROM (SELECT Tab.Id AS Id FROM tab WHERE Tab.Id = {[id]}) *)
17 else 1 + sillyRecursive {Id = id, FooBar = fooBar - 1} 15 (* AS Q); *)
16 (* return <xml><body> *)
17 (* cacheAlt *)
18 (* {case res of *)
19 (* None => <xml>?</xml> *)
20 (* | Some row => <xml>{[row.Q.Id]}</xml>} *)
21 (* </body></xml> *)
18 22
19 fun cacheR (r : {Id : int, FooBar : int}) = 23 (* fun sillyRecursive {Id = id : int, FooBar = fooBar} = *)
20 res <- oneOrNoRows (SELECT tab.Val 24 (* if fooBar <= 0 *)
21 FROM tab 25 (* then 0 *)
22 WHERE tab.Id = {[r.Id]}); 26 (* else 1 + sillyRecursive {Id = id, FooBar = fooBar - 1} *)
23 return <xml><body> 27
24 cacheR {[r.FooBar]} 28 (* fun cacheR (r : {Id : int, FooBar : int}) = *)
25 {case res of 29 (* res <- oneOrNoRows (SELECT tab.Val *)
26 None => <xml>?</xml> 30 (* FROM tab *)
27 | Some row => <xml>{[row.Tab.Val]}</xml>} 31 (* WHERE tab.Id = {[r.Id]}); *)
28 </body></xml> 32 (* return <xml><body> *)
33 (* cacheR {[r.FooBar]} *)
34 (* {case res of *)
35 (* None => <xml>?</xml> *)
36 (* | Some row => <xml>{[row.Tab.Val]}</xml>} *)
37 (* </body></xml> *)
29 38
30 (* fun cache2 id v = *) 39 (* fun cache2 id v = *)
31 (* res <- oneOrNoRows (SELECT tab.Val *) 40 (* res <- oneOrNoRows (SELECT tab.Val *)
32 (* FROM tab *) 41 (* FROM tab *)
33 (* WHERE tab.Id = {[id]} AND tab.Val = {[v]}); *) 42 (* WHERE tab.Id = {[id]} AND tab.Val = {[v]}); *)
58 WHERE Id = {[id]} OR Id = {[id - 1]} OR Id = {[id + 1]}); 67 WHERE Id = {[id]} OR Id = {[id - 1]} OR Id = {[id + 1]});
59 return <xml><body> 68 return <xml><body>
60 Changed {[id]}! 69 Changed {[id]}!
61 </body></xml> 70 </body></xml>
62 71
63 fun flash id = 72 (* fun flash id = *)
64 dml (UPDATE tab 73 (* dml (UPDATE tab *)
65 SET Foo = Val 74 (* SET Foo = Val *)
66 WHERE Id = {[id]} OR Id = {[id - 1]} OR Id = {[id + 1]}); 75 (* WHERE Id = {[id]} OR Id = {[id - 1]} OR Id = {[id + 1]}); *)
67 return <xml><body> 76 (* return <xml><body> *)
68 Maybe changed {[id]}? 77 (* Maybe changed {[id]}? *)
69 </body></xml> 78 (* </body></xml> *)
70 79
71 fun floosh id = 80 (* fun floosh id = *)
72 dml (UPDATE tab 81 (* dml (UPDATE tab *)
73 SET Id = {[id + 1]} 82 (* SET Id = {[id + 1]} *)
74 WHERE Id = {[id]}); 83 (* WHERE Id = {[id]} OR Id = {[id - 1]} OR Id = {[id + 1]}); *)
75 return <xml><body> 84 (* return <xml><body> *)
76 Shifted {[id]}! 85 (* Shifted {[id]}! *)
77 </body></xml> 86 (* </body></xml> *)
78 87
79 (* val flush17 = *) 88 (* val flush17 = *)
80 (* dml (UPDATE tab *) 89 (* dml (UPDATE tab *)
81 (* SET Val = Val * (Id + 2) / Val - 3 *) 90 (* SET Val = Val * (Id + 2) / Val - 3 *)
82 (* WHERE Id = 17); *) 91 (* WHERE Id = 17); *)