comparison tests/blob.ur @ 742:43553c93dd8c

Reading blobs from the database
author Adam Chlipala <adamc@hcoop.net>
date Sun, 26 Apr 2009 10:45:59 -0400
parents b302b6e35f93
children ee2feab275db
comparison
equal deleted inserted replaced
741:f7e2026dd5ae 742:43553c93dd8c
1 sequence s 1 sequence s
2 table t : { Id : int, Nam : option string, Data : blob, Desc : string, Typ : string } 2 table t : { Id : int, Nam : option string, Data : blob, Desc : string, Typ : string }
3
4 fun view id =
5 r <- oneRow (SELECT t.Data, t.Typ FROM t WHERE t.Id = {[id]});
6 returnBlob r.T.Data (blessMime r.T.Typ)
3 7
4 fun save r = 8 fun save r =
5 id <- nextval s; 9 id <- nextval s;
6 dml (INSERT INTO t (Id, Nam, Data, Desc, Typ) 10 dml (INSERT INTO t (Id, Nam, Data, Desc, Typ)
7 VALUES ({[id]}, {[fileName r.Data]}, {[fileData r.Data]}, {[r.Desc]}, {[fileMimeType r.Data]})); 11 VALUES ({[id]}, {[fileName r.Data]}, {[fileData r.Data]}, {[r.Desc]}, {[fileMimeType r.Data]}));
8 main () 12 main ()
9 13
10 and main () = return <xml><body> 14 and main () =
11 <form> 15 ls <- queryX (SELECT t.Id, t.Desc FROM t ORDER BY t.Desc)
12 <textbox{#Desc}/> 16 (fn r => <xml><li><a link={view r.T.Id}>{[r.T.Desc]}</a></li></xml>);
13 <upload{#Data}/> 17 return <xml><body>
14 <submit action={save}/> 18 {ls}
15 </form> 19
16 </body></xml> 20 <br/>
21
22 <form>
23 <textbox{#Desc}/>
24 <upload{#Data}/>
25 <submit action={save}/>
26 </form>
27 </body></xml>