Mercurial > urweb
comparison tests/blobOpt.ur @ 743:cd67c3a942e3
Handling nullable blobs
author | Adam Chlipala <adamc@hcoop.net> |
---|---|
date | Sun, 26 Apr 2009 10:53:36 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
742:43553c93dd8c | 743:cd67c3a942e3 |
---|---|
1 sequence s | |
2 table t : { Id : int, Data : option blob, Typ : string } | |
3 | |
4 fun view id = | |
5 r <- oneRow (SELECT t.Data, t.Typ FROM t WHERE t.Id = {[id]}); | |
6 case r.T.Data of | |
7 None => return <xml>This one's empty.</xml> | |
8 | Some data => returnBlob data (blessMime r.T.Typ) | |
9 | |
10 fun save r = | |
11 id <- nextval s; | |
12 dml (INSERT INTO t (Id, Data, Typ) | |
13 VALUES ({[id]}, {[Some (fileData r.Data)]}, {[fileMimeType r.Data]})); | |
14 main () | |
15 | |
16 and saveEmpty () = | |
17 id <- nextval s; | |
18 dml (INSERT INTO t (Id, Data, Typ) | |
19 VALUES ({[id]}, {[None]}, "bogus")); | |
20 main () | |
21 | |
22 and main () = | |
23 ls <- queryX (SELECT t.Id FROM t) | |
24 (fn r => <xml><li><a link={view r.T.Id}>{[r.T.Id]}</a></li></xml>); | |
25 return <xml><body> | |
26 {ls} | |
27 | |
28 <br/> | |
29 | |
30 <form> | |
31 <upload{#Data}/> | |
32 <submit action={save}/> | |
33 </form> | |
34 | |
35 <form> | |
36 <submit action={saveEmpty}/> | |
37 </form> | |
38 </body></xml> |