summaryrefslogtreecommitdiff
path: root/tests/blobOpt.ur
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adamc@hcoop.net>2009-04-26 10:53:36 -0400
committerGravatar Adam Chlipala <adamc@hcoop.net>2009-04-26 10:53:36 -0400
commit861f4c0a3619812bb56f2f6b5dd5cb3a13b05bd4 (patch)
tree741eea8099c56fc61347f867ce538744a95c2b8f /tests/blobOpt.ur
parent7bd2bc26389467f685958601cff2708751764515 (diff)
Handling nullable blobs
Diffstat (limited to 'tests/blobOpt.ur')
-rw-r--r--tests/blobOpt.ur38
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/blobOpt.ur b/tests/blobOpt.ur
new file mode 100644
index 00000000..261ce226
--- /dev/null
+++ b/tests/blobOpt.ur
@@ -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>