diff options
author | Adam Chlipala <adam@chlipala.net> | 2011-10-15 09:04:41 -0400 |
---|---|---|
committer | Adam Chlipala <adam@chlipala.net> | 2011-10-15 09:04:41 -0400 |
commit | e2a639a782d2c7be434b819156fb924c7d955f12 (patch) | |
tree | 49c7507ba8ae3e2d432d2b6b22e33bf22564142d | |
parent | 8a167261f4de68926907c3cc97f8252957274bff (diff) |
For new IF, fix Monoize typing and add to manual
-rw-r--r-- | doc/manual.tex | 10 | ||||
-rw-r--r-- | src/monoize.sml | 4 | ||||
-rw-r--r-- | tests/sql_if.ur | 6 | ||||
-rw-r--r-- | tests/sql_if.urp | 4 | ||||
-rw-r--r-- | tests/sql_if.urs | 1 |
5 files changed, 23 insertions, 2 deletions
diff --git a/doc/manual.tex b/doc/manual.tex index d98029af..2c1cecc2 100644 --- a/doc/manual.tex +++ b/doc/manual.tex @@ -1783,6 +1783,15 @@ $$\begin{array}{l} \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 @@ $$\begin{array}{rrcll} &&& 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 --git a/src/monoize.sml b/src/monoize.sml index e33513f8..e570b4cb 100644 --- a/src/monoize.sml +++ b/src/monoize.sml @@ -2816,9 +2816,9 @@ fun monoExp (env, st, fm) (all as (e, loc)) = 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 --git a/tests/sql_if.ur b/tests/sql_if.ur new file mode 100644 index 00000000..4413e762 --- /dev/null +++ b/tests/sql_if.ur @@ -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 => <xml><li>{[r.T.A]}, {[r.T.B]}</li></xml>); + return <xml><body>{x}</body></xml> diff --git a/tests/sql_if.urp b/tests/sql_if.urp new file mode 100644 index 00000000..49e846f3 --- /dev/null +++ b/tests/sql_if.urp @@ -0,0 +1,4 @@ +database dbname=sql_if +sql sql_if.sql + +sql_if diff --git a/tests/sql_if.urs b/tests/sql_if.urs new file mode 100644 index 00000000..6ac44e0b --- /dev/null +++ b/tests/sql_if.urs @@ -0,0 +1 @@ +val main : unit -> transaction page |