# HG changeset patch # User Adam Chlipala # Date 1318683881 14400 # Node ID 34364e383bed89e6670701df3aded756a8a092e8 # Parent 5530a8075b62ef11f4177931c2d70b05bfc75ebb For new IF, fix Monoize typing and add to manual diff -r 5530a8075b62 -r 34364e383bed doc/manual.tex --- a/doc/manual.tex Fri Oct 14 02:33:03 2011 -0430 +++ b/doc/manual.tex Sat Oct 15 09:04:41 2011 -0400 @@ -1783,6 +1783,15 @@ \hspace{.1in} \to \mt{nullify} \; \mt{t} \; \mt{nt} \to \mt{sql\_query} \; \mt{tables} \; \mt{agg} \; [\mt{nm} = \mt{t}] \to \mt{sql\_exp} \; \mt{tables} \; \mt{agg} \; \mt{exps} \; \mt{nt} \end{array}$$ +There is also an \cd{IF..THEN..ELSE..} construct that is compiled into standard SQL \cd{CASE} expressions. +$$\begin{array}{l} +\mt{val} \; \mt{sql\_if\_then\_else} : \mt{tables} ::: \{\{\mt{Type}\}\} \to \mt{agg} ::: \{\{\mt{Type}\}\} \to \mt{exps} ::: \{\mt{Type}\} \to \mt{t} ::: \mt{Type} \\ +\hspace{.1in} \to \mt{sql\_exp} \; \mt{tables} \; \mt{agg} \; \mt{exps} \; \mt{bool} \\ +\hspace{.1in} \to \mt{sql\_exp} \; \mt{tables} \; \mt{agg} \; \mt{exps} \; \mt{t} \\ +\hspace{.1in} \to \mt{sql\_exp} \; \mt{tables} \; \mt{agg} \; \mt{exps} \; \mt{t} \\ +\hspace{.1in} \to \mt{sql\_exp} \; \mt{tables} \; \mt{agg} \; \mt{exps} \; \mt{t} +\end{array}$$ + \texttt{FROM} clauses are specified using a type family, whose arguments are the free table variables and the table variables bound by this clause. $$\begin{array}{l} \mt{con} \; \mt{sql\_from\_items} :: \{\{\mt{Type}\}\} \to \{\{\mt{Type}\}\} \to \mt{Type} \\ @@ -2133,6 +2142,7 @@ &&& E \; b \; E & \textrm{binary operators} \\ &&& \mt{COUNT}(\ast) & \textrm{count number of rows} \\ &&& a(E) & \textrm{other aggregate function} \\ + &&& \mt{IF} \; E \; \mt{THEN} \; E \; \mt{ELSE} \; E & \textrm{conditional} \\ &&& (Q) & \textrm{subquery (must return a single expression column)} \\ &&& (E) & \textrm{explicit precedence} \\ \textrm{Nullary operators} & n &::=& \mt{CURRENT\_TIMESTAMP} \\ diff -r 5530a8075b62 -r 34364e383bed src/monoize.sml --- a/src/monoize.sml Fri Oct 14 02:33:03 2011 -0430 +++ b/src/monoize.sml Sat Oct 15 09:04:41 2011 -0400 @@ -2816,9 +2816,9 @@ val s = (L'.TFfi ("Basis", "string"), loc) fun sc s = (L'.EPrim (Prim.String s), loc) in - ((L'.EAbs ("if", s, (L'.TFun (s, s), loc), + ((L'.EAbs ("if", s, (L'.TFun (s, (L'.TFun (s, s), loc)), loc), (L'.EAbs ("then", s, (L'.TFun (s, s), loc), - (L'.EAbs ("else", s, (L'.TFun (s, s), loc), + (L'.EAbs ("else", s, s, strcat [sc "(CASE WHEN (", (L'.ERel 2, loc), sc ") THEN (", diff -r 5530a8075b62 -r 34364e383bed tests/sql_if.ur --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/sql_if.ur Sat Oct 15 09:04:41 2011 -0400 @@ -0,0 +1,6 @@ +table t : { A : int, B : int } + +fun main () = + x <- queryX (SELECT * FROM t WHERE IF t.A = 6 THEN t.B < 2 ELSE t.B > 5) + (fn r =>
  • {[r.T.A]}, {[r.T.B]}
  • ); + return {x} diff -r 5530a8075b62 -r 34364e383bed tests/sql_if.urp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/sql_if.urp Sat Oct 15 09:04:41 2011 -0400 @@ -0,0 +1,4 @@ +database dbname=sql_if +sql sql_if.sql + +sql_if diff -r 5530a8075b62 -r 34364e383bed tests/sql_if.urs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/sql_if.urs Sat Oct 15 09:04:41 2011 -0400 @@ -0,0 +1,1 @@ +val main : unit -> transaction page