view tests/dbupload2.ur @ 2262:34ad83d9b729

Fix recording bugs to do with nesting and buffer reallocation. Stop MonoFooify printing spurious errors.
author Ziv Scully <ziv@mit.edu>
date Wed, 07 Oct 2015 08:58:08 -0400
parents 229a299d739d
children
line wrap: on
line source
table t : { Id : int, Blob : blob, MimeType : string }
sequence s

fun getImage id : transaction page =
    r <- oneRow1 (SELECT t.Blob, t.MimeType
                  FROM t
                  WHERE t.Id = {[id]});
    returnBlob r.Blob (blessMime r.MimeType)

fun handle (r : {File:file, Param:string}) =
    id <- nextval s;
    dml (INSERT INTO t (Id, Blob, MimeType)
         VALUES ({[id]}, {[fileData r.File]}, {[fileMimeType r.File]}));
    debug ("Text is " ^ r.Param);
    main ()

and main () : transaction page =
    x <- queryX1 (SELECT t.Id FROM t)
                 (fn r => <xml><img src={url (getImage r.Id)}/>
</xml>);
    return <xml><body>
      <form>
      <upload{#File}/>
      <textbox{#Param} value="text"/>
      <submit action={handle}/>
      </form>
      <hr/>
      {x}
    </body></xml>