Mercurial > urweb
view 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 |
line wrap: on
line source
sequence s table t : { Id : int, Nam : option string, Data : blob, Desc : string, Typ : string } fun view id = r <- oneRow (SELECT t.Data, t.Typ FROM t WHERE t.Id = {[id]}); returnBlob r.T.Data (blessMime r.T.Typ) fun save r = id <- nextval s; dml (INSERT INTO t (Id, Nam, Data, Desc, Typ) VALUES ({[id]}, {[fileName r.Data]}, {[fileData r.Data]}, {[r.Desc]}, {[fileMimeType r.Data]})); main () and main () = ls <- queryX (SELECT t.Id, t.Desc FROM t ORDER BY t.Desc) (fn r => <xml><li><a link={view r.T.Id}>{[r.T.Desc]}</a></li></xml>); return <xml><body> {ls} <br/> <form> <textbox{#Desc}/> <upload{#Data}/> <submit action={save}/> </form> </body></xml>