Mercurial > urweb
annotate caching-tests/test.ur @ 2237:e79ef5792c8b
Fix bug in redundancy checking and use finer formula for UPDATE statements.
author | Ziv Scully <ziv@mit.edu> |
---|---|
date | Sun, 05 Jul 2015 23:57:28 -0700 |
parents | fab8c1f131a5 |
children | 7f92d70a326e |
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@2236 | 18 WHERE Id = {[id]} OR Id = {[id - 1]} 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> *) |