summaryrefslogtreecommitdiff
path: root/caching-tests/bench.ur
blob: 0c7bb674606639059bb98850aa5057b6b23cae6a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
table tab : {Id : int, Val : int} PRIMARY KEY Id

fun check id =
    res <- oneOrNoRows (SELECT tab.Val FROM tab WHERE tab.Id = {[id]});
    return <xml><body>
      {case res of
           None => <xml>?</xml>
         | Some row => <xml>{[row.Tab.Val]}</xml>}
    </body></xml>

fun flush id =
    dml (UPDATE tab SET Val = Val + 1 WHERE Id = {[id]});
    return <xml><body>
      Changed {[id]}!
    </body></xml>

fun main x y =
    r <- rand;
    let
        val id = r % x
        val doFlush = (r / x) % y = 0
    in
        if doFlush then flush id else check id
    end