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