summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adam@chlipala.net>2011-02-03 21:04:12 -0500
committerGravatar Adam Chlipala <adam@chlipala.net>2011-02-03 21:04:12 -0500
commit58c927541d3960c0bca5636c05e499246d3cecef (patch)
tree0d7561a584be03f1fbd5a3297a101e3c54bf7ba9
parent426f4427ff7a2d58e86f533ad8bb79a0b6b89d31 (diff)
Subqueries may always return NULL
-rw-r--r--doc/manual.tex4
-rw-r--r--lib/ur/basis.urs5
-rw-r--r--src/monoize.sml13
3 files changed, 13 insertions, 9 deletions
diff --git a/doc/manual.tex b/doc/manual.tex
index ad6edeb9..c39d92df 100644
--- a/doc/manual.tex
+++ b/doc/manual.tex
@@ -1726,8 +1726,8 @@ $$\begin{array}{l}
Any SQL query that returns single columns may be turned into a subquery expression.
$$\begin{array}{l}
-\mt{val} \; \mt{sql\_subquery} : \mt{tables} ::: \{\{\mt{Type}\}\} \to \mt{agg} ::: \{\{\mt{Type}\}\} \to \mt{exps} ::: \{\mt{Type}\} \to \mt{nm} ::: \mt{Name} \to \mt{t} ::: \mt{Type} \\
-\hspace{.1in} \to \mt{sql\_query} \; \mt{tables} \; \mt{agg} \; [\mt{nm} = \mt{t}] \to \mt{sql\_exp} \; \mt{tables} \; \mt{agg} \; \mt{exps} \; \mt{t}
+\mt{val} \; \mt{sql\_subquery} : \mt{tables} ::: \{\{\mt{Type}\}\} \to \mt{agg} ::: \{\{\mt{Type}\}\} \to \mt{exps} ::: \{\mt{Type}\} \to \mt{nm} ::: \mt{Name} \to \mt{t} ::: \mt{Type} \to \mt{nt} ::: \mt{Type} \\
+\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}$$
\texttt{FROM} clauses are specified using a type family, whose arguments are the free table variables and the table variables bound by this clause.
diff --git a/lib/ur/basis.urs b/lib/ur/basis.urs
index da703d40..795b4f9a 100644
--- a/lib/ur/basis.urs
+++ b/lib/ur/basis.urs
@@ -529,9 +529,10 @@ val sql_nullable : tables ::: {{Type}} -> agg ::: {{Type}} -> exps ::: {Type} ->
-> sql_exp tables agg exps t
-> sql_exp tables agg exps (option t)
-val sql_subquery : tables ::: {{Type}} -> agg ::: {{Type}} -> exps ::: {Type} -> nm ::: Name -> t ::: Type
+val sql_subquery : tables ::: {{Type}} -> agg ::: {{Type}} -> exps ::: {Type} -> nm ::: Name -> t ::: Type -> nt ::: Type
+ -> nullify t nt
-> sql_query tables agg [] [nm = t]
- -> sql_exp tables agg exps t
+ -> sql_exp tables agg exps nt
(*** Executing queries *)
diff --git a/src/monoize.sml b/src/monoize.sml
index de518c81..9f76dbee 100644
--- a/src/monoize.sml
+++ b/src/monoize.sml
@@ -2796,7 +2796,9 @@ fun monoExp (env, st, fm) (all as (e, loc)) =
(L.ECApp (
(L.ECApp (
(L.ECApp (
- (L.EFfi ("Basis", "sql_subquery"), _),
+ (L.ECApp (
+ (L.EFfi ("Basis", "sql_subquery"), _),
+ _), _),
_), _),
_), _),
_), _),
@@ -2806,10 +2808,11 @@ 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 ("x", s, s,
- strcat [sc "(",
- (L'.ERel 0, loc),
- sc ")"]), loc),
+ ((L'.EAbs ("_", (L'.TRecord [], loc), (L'.TFun (s, s), loc),
+ (L'.EAbs ("x", s, s,
+ strcat [sc "(",
+ (L'.ERel 0, loc),
+ sc ")"]), loc)), loc),
fm)
end