annotate 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
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@2235 14
ziv@2213 15 fun flush id =
ziv@2235 16 dml (UPDATE tab
ziv@2235 17 SET Val = 42
ziv@2235 18 WHERE Id = {[id]} OR Id = {[id + 1]});
ziv@2204 19 return <xml><body>
ziv@2235 20 Changed {[id]}!
ziv@2204 21 </body></xml>
ziv@2234 22
ziv@2235 23 (* fun flush id = *)
ziv@2235 24 (* res <- oneOrNoRows (SELECT tab.Val *)
ziv@2235 25 (* FROM tab *)
ziv@2235 26 (* WHERE tab.Id = {[id]}); *)
ziv@2235 27 (* (case res of *)
ziv@2235 28 (* None => dml (INSERT INTO tab (Id, Val) *)
ziv@2235 29 (* VALUES ({[id]}, 0)) *)
ziv@2235 30 (* | Some row => dml (UPDATE tab *)
ziv@2235 31 (* SET Val = {[row.Tab.Val + 1]} *)
ziv@2235 32 (* WHERE Id = {[id]} OR Id = {[id + 1]})); *)
ziv@2235 33 (* return <xml><body> *)
ziv@2235 34 (* {case res of *)
ziv@2235 35 (* None => <xml>Initialized {[id]}!</xml> *)
ziv@2235 36 (* | Some row => <xml>Incremented {[id]}!</xml>} *)
ziv@2235 37 (* </body></xml> *)