# HG changeset patch # User Adam Chlipala # Date 1225394197 14400 # Node ID 19d7f79cd584c5427fad1c554178a1e1710333f9 # Parent 322c8620bbdfbc56083429df3d1f4208ebb00d52 Time MIN/MAX diff -r 322c8620bbdf -r 19d7f79cd584 lib/top.ur --- a/lib/top.ur Thu Oct 30 15:11:37 2008 -0400 +++ b/lib/top.ur Thu Oct 30 15:16:37 2008 -0400 @@ -157,3 +157,11 @@ query q (fn fs _ => return (Some fs)) None + +fun oneRow (tables ::: {{Type}}) (exps ::: {Type}) + (q : sql_query tables exps) [tables ~ exps] = + o <- oneOrNoRows q; + return (case o of + None => error Query returned no rows + | Some r => r) + diff -r 322c8620bbdf -r 19d7f79cd584 lib/top.urs --- a/lib/top.urs Thu Oct 30 15:11:37 2008 -0400 +++ b/lib/top.urs Thu Oct 30 15:16:37 2008 -0400 @@ -116,3 +116,13 @@ [[nm] ~ acc] => [nm = $fields] ++ acc) [] tables)) + +val oneRow : tables ::: {{Type}} -> exps ::: {Type} + -> sql_query tables exps + -> fn [tables ~ exps] => + transaction + $(exps + ++ fold (fn nm (fields :: {Type}) acc + [[nm] ~ acc] => + [nm = $fields] ++ acc) + [] tables) diff -r 322c8620bbdf -r 19d7f79cd584 tests/time.ur --- a/tests/time.ur Thu Oct 30 15:11:37 2008 -0400 +++ b/tests/time.ur Thu Oct 30 15:16:37 2008 -0400 @@ -7,7 +7,9 @@ dml (INSERT INTO t (Id, Time) VALUES (42, {now})); xml <- queryX (SELECT * FROM t) (fn r => {[r.T.Id]}: {[r.T.Time]}
); + minMax <- oneRow (SELECT MIN(t.Time) AS Min, MAX(t.Time) AS Max FROM t); return {xml} - {[now]}, {[now = now]}, {[now = later]}, {[later < now]}, {[now < later]} + {[now]}, {[now = now]}, {[now = later]}, {[later < now]}, {[now < later]}
+ {[minMax.Min]}, {[minMax.Max]}