view tests/blob.ur @ 746:2c7244c066f1

sql_ufunc and octet_length
author Adam Chlipala <>
date Sun, 26 Apr 2009 12:35:45 -0400
parents ee2feab275db
children 034eeb099564
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, octet_length(t.Data) AS Len FROM t ORDER BY t.Desc)
          (fn r => <xml><li><a link={view r.T.Id}>{[r.T.Desc]} ({[r.Len]})</a></li></xml>);
    return <xml><body>


        <submit action={save}/>