annotate caching-tests/test.ur @ 2242:200a7ed4343b

Add parameterless query to caching test.
author Ziv Scully <ziv@mit.edu>
date Sun, 19 Jul 2015 19:12:50 -0700
parents f70a91f7810d
children f7bc7c11a656
rev   line source
ziv@2213 1 table tab : {Id : int, Val : 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@2213 14 fun flush id =
ziv@2239 15 dml (UPDATE tab
ziv@2239 16 SET Val = Val * (Id + 2) / Val - 3
ziv@2239 17 WHERE Id = {[id]} OR Id = {[id - 1]} OR Id = {[id + 1]});
ziv@2204 18 return <xml><body>
ziv@2235 19 Changed {[id]}!
ziv@2204 20 </body></xml>
ziv@2234 21
ziv@2242 22 val flush17 =
ziv@2242 23 dml (UPDATE tab
ziv@2242 24 SET Val = Val * (Id + 2) / Val - 3
ziv@2242 25 WHERE Id = 17);
ziv@2242 26 return <xml><body>
ziv@2242 27 Changed specifically 17!
ziv@2242 28 </body></xml>
ziv@2242 29
ziv@2235 30 (* fun flush id = *)
ziv@2235 31 (* res <- oneOrNoRows (SELECT tab.Val *)
ziv@2235 32 (* FROM tab *)
ziv@2235 33 (* WHERE tab.Id = {[id]}); *)
ziv@2235 34 (* (case res of *)
ziv@2235 35 (* None => dml (INSERT INTO tab (Id, Val) *)
ziv@2235 36 (* VALUES ({[id]}, 0)) *)
ziv@2235 37 (* | Some row => dml (UPDATE tab *)
ziv@2235 38 (* SET Val = {[row.Tab.Val + 1]} *)
ziv@2235 39 (* WHERE Id = {[id]} OR Id = {[id + 1]})); *)
ziv@2235 40 (* return <xml><body> *)
ziv@2235 41 (* {case res of *)
ziv@2235 42 (* None => <xml>Initialized {[id]}!</xml> *)
ziv@2235 43 (* | Some row => <xml>Incremented {[id]}!</xml>} *)
ziv@2235 44 (* </body></xml> *)