summaryrefslogtreecommitdiff
path: root/tests/dbuploadOpt.ur
diff options
context:
space:
mode:
authorGravatar Benjamin Barenblat <bbaren@mit.edu>2020-05-31 18:29:03 -0400
committerGravatar Benjamin Barenblat <bbaren@mit.edu>2020-05-31 18:29:03 -0400
commit6cc104634ef64be3be88c1fccbe98208d95d8a1a (patch)
tree9001e5333e808808125978a52669a8bff3639438 /tests/dbuploadOpt.ur
parent82fde07cef0e41b700b9a30137562eb05f2f2c6d (diff)
parentc2f1e1096f602b1cbd4531352f3e1ea6d656a186 (diff)
Merge branch 'dfsg_clean'
Diffstat (limited to 'tests/dbuploadOpt.ur')
-rw-r--r--tests/dbuploadOpt.ur27
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/dbuploadOpt.ur b/tests/dbuploadOpt.ur
new file mode 100644
index 00000000..466b49f3
--- /dev/null
+++ b/tests/dbuploadOpt.ur
@@ -0,0 +1,27 @@
+table t : { Id : int, Blob : option blob, MimeType : string }
+sequence s
+
+fun getImage id : transaction page =
+ r <- oneRow1 (SELECT t.Blob, t.MimeType
+ FROM t
+ WHERE t.Id = {[id]});
+ case r.Blob of
+ None => error <xml>Oh no!</xml>
+ | Some blob => returnBlob blob (blessMime r.MimeType)
+
+fun main () : transaction page =
+ let
+ fun handle r =
+ id <- nextval s;
+ dml (INSERT INTO t (Id, Blob, MimeType)
+ VALUES ({[id]}, {[if fileMimeType r.File = "image/jpeg" then Some (fileData r.File) else None]}, {[fileMimeType r.File]}));
+ main ()
+ in
+ x <- queryX1 (SELECT t.Id FROM t)
+ (fn r => <xml><img src={url (getImage r.Id)}/><br/></xml>);
+ return <xml><body>
+ <form><upload{#File}/> <submit action={handle}/></form>
+ <hr/>
+ {x}
+ </body></xml>
+ end