adamc@649: datatype list t = Nil | Cons of t * list t
adamc@649:
adamc@649: table t : {Id : int, A : string}
adamc@708: PRIMARY KEY Id
adamc@649:
adamc@649: fun allRows () =
adamc@649: query (SELECT * FROM t)
adamc@649: (fn r acc => return (Cons ((r.T.Id, r.T.A), acc)))
adamc@649: Nil
adamc@649:
adamc@649: fun doBatch ls =
adamc@649: case ls of
adamc@649: Nil => return ()
adamc@649: | Cons ((id, a), ls') =>
adamc@649: dml (INSERT INTO t (Id, A) VALUES ({[id]}, {[a]}));
adamc@649: doBatch ls'
adamc@649:
adamc@649: fun del id =
adamc@649: dml (DELETE FROM t WHERE t.Id = {[id]})
adamc@649:
adamc@649: fun show withDel lss =
adamc@649: let
adamc@649: fun show' ls =
adamc@649: case ls of
adamc@649: Nil =>
adamc@649: | Cons ((id, a), ls) =>
adamc@649:
{[id]}
{[a]}
{if withDel then
adamc@649:
adamc@649: else
adamc@649: }
adamc@649: {show' ls}
adamc@649:
adamc@649: in
adamc@649:
adamc@649:
Id
A
adamc@649: {show' ls}
adamc@649:
}/>
adamc@649: end
adamc@649:
adamc@733: fun action () =
adamc@649: lss <- source Nil;
adamc@649: batched <- source Nil;
adamc@649:
adamc@649: id <- source "";
adamc@649: a <- source "";
adamc@649:
adamc@649: let
adamc@649: fun add () =
adamc@649: id <- get id;
adamc@649: a <- get a;
adamc@649: ls <- get batched;
adamc@649:
adamc@649: set batched (Cons ((readError id, a), ls))
adamc@649:
adamc@649: fun exec () =
adamc@649: ls <- get batched;
adamc@649:
adamc@649: doBatch ls;
adamc@649: set batched Nil
adamc@649: in
adamc@649: return
adamc@649: