Mercurial > urweb
comparison tests/nested.ur @ 880:8e9f2d247dba
Testing nested queries
author | Adam Chlipala <adamc@hcoop.net> |
---|---|
date | Fri, 17 Jul 2009 12:25:34 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
879:b2a175a0f2ef | 880:8e9f2d247dba |
---|---|
1 table t : {A : int, B : int} | |
2 | |
3 fun init () = | |
4 dml (DELETE FROM t WHERE TRUE); | |
5 dml (INSERT INTO t (A, B) VALUES (1, 2)); | |
6 dml (INSERT INTO t (A, B) VALUES (2, 3)) | |
7 | |
8 fun easy () = | |
9 queryX' (SELECT MAX(t.A) AS M FROM t) | |
10 (fn r => | |
11 queryX (SELECT * FROM t WHERE t.A = {[r.M]}) | |
12 (fn r => <xml>({[r.T.A]}, {[r.T.B]})</xml>)) | |
13 | |
14 fun hard id = | |
15 queryX' (SELECT t.B AS N FROM t WHERE t.A = {[id]}) | |
16 (fn r => | |
17 b <- hard r.N; | |
18 return <xml>({[id]}, {[r.N]}); {b}</xml>) | |
19 | |
20 fun doit () = | |
21 init (); | |
22 b1 <- easy (); | |
23 b2 <- hard 1; | |
24 return <xml><body> | |
25 {b1}<br/> | |
26 {b2} | |
27 </body></xml> | |
28 | |
29 fun main () = return <xml><body><form><submit action={doit}/></form></body></xml> |