Mercurial > urweb
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/blobOpt.ur Sun Apr 26 10:53:36 2009 -0400 @@ -0,0 +1,38 @@ +sequence s +table t : { Id : int, Data : option blob, Typ : string } + +fun view id = + r <- oneRow (SELECT t.Data, t.Typ FROM t WHERE t.Id = {[id]}); + case r.T.Data of + None => return <xml>This one's empty.</xml> + | Some data => returnBlob data (blessMime r.T.Typ) + +fun save r = + id <- nextval s; + dml (INSERT INTO t (Id, Data, Typ) + VALUES ({[id]}, {[Some (fileData r.Data)]}, {[fileMimeType r.Data]})); + main () + +and saveEmpty () = + id <- nextval s; + dml (INSERT INTO t (Id, Data, Typ) + VALUES ({[id]}, {[None]}, "bogus")); + main () + +and main () = + ls <- queryX (SELECT t.Id FROM t) + (fn r => <xml><li><a link={view r.T.Id}>{[r.T.Id]}</a></li></xml>); + return <xml><body> + {ls} + + <br/> + + <form> + <upload{#Data}/> + <submit action={save}/> + </form> + + <form> + <submit action={saveEmpty}/> + </form> + </body></xml>