annotate caching-tests/test.ur @ 2305:9083b44bad0a

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