Mercurial > urweb
changeset 1070:e933297c4e24
Tweaking SQL parsing and typing
author | Adam Chlipala <adamc@hcoop.net> |
---|---|
date | Sun, 13 Dec 2009 10:13:06 -0500 |
parents | 757397bb9609 |
children | 26197c957ad6 |
files | CHANGELOG lib/ur/basis.urs src/monoize.sml src/urweb.grm tests/relops.ur tests/relops.urp |
diffstat | 6 files changed, 33 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/CHANGELOG Sat Dec 12 14:51:10 2009 -0500 +++ b/CHANGELOG Sun Dec 13 10:13:06 2009 -0500 @@ -3,6 +3,9 @@ ======== - Reifying expressions as URLs and redirecting to them explicitly +- More syntactic sugar for SQL +- Typing of SQL queries no longer exposes which tables were used in joins but + had none of their fields projected ======== 20091203
--- a/lib/ur/basis.urs Sat Dec 12 14:51:10 2009 -0500 +++ b/lib/ur/basis.urs Sun Dec 13 10:13:06 2009 -0500 @@ -320,12 +320,14 @@ -> grouped ::: {{Type}} -> selectedFields ::: {{Type}} -> selectedExps ::: {Type} - -> {Distinct : bool, + -> empties :: {Unit} + -> [empties ~ selectedFields] + => {Distinct : bool, From : sql_from_items tables, Where : sql_exp tables [] [] bool, GroupBy : sql_subset tables grouped, Having : sql_exp grouped tables [] bool, - SelectFields : sql_subset grouped selectedFields, + SelectFields : sql_subset grouped (map (fn _ => []) empties ++ selectedFields), SelectExps : $(map (sql_exp grouped tables []) selectedExps) } -> sql_query1 tables selectedFields selectedExps
--- a/src/monoize.sml Sat Dec 12 14:51:10 2009 -0500 +++ b/src/monoize.sml Sun Dec 13 10:13:06 2009 -0500 @@ -1772,11 +1772,13 @@ (L.ECApp ( (L.ECApp ( (L.ECApp ( - (L.EFfi ("Basis", "sql_query1"), _), - (L.CRecord (_, tables), _)), _), - (L.CRecord (_, grouped), _)), _), - (L.CRecord (_, stables), _)), _), - sexps) => + (L.ECApp ( + (L.EFfi ("Basis", "sql_query1"), _), + (L.CRecord (_, tables), _)), _), + (L.CRecord (_, grouped), _)), _), + (L.CRecord (_, stables), _)), _), + sexps), _), + _) => let fun sc s = (L'.EPrim (Prim.String s), loc) val s = (L'.TFfi ("Basis", "string"), loc)
--- a/src/urweb.grm Sat Dec 12 14:51:10 2009 -0500 +++ b/src/urweb.grm Sun Dec 13 10:13:06 2009 -0500 @@ -1169,6 +1169,7 @@ | LPAREN query RPAREN (query) | LPAREN CWHERE sqlexp RPAREN (sqlexp) | LPAREN SQL sqlexp RPAREN (sqlexp) + | LPAREN FROM tables RPAREN (#2 tables) | LPAREN INSERT INTO texp LPAREN fields RPAREN VALUES LPAREN sqlexps RPAREN RPAREN (let @@ -1449,9 +1450,10 @@ (let val loc = s (SELECTleft, tablesright) - val (sel, exps) = + val (empties, sel, exps) = case select of - Star => (map (fn nm => + Star => ([], + map (fn nm => (nm, (CTuple [(CWild (KRecord (KType, loc), loc), loc), (CRecord [], loc)], @@ -1461,8 +1463,12 @@ let val tabs = map (fn nm => (nm, (CRecord [], loc))) (#1 tables) val (tabs, exps) = foldl (amend_select loc) (tabs, []) sis + val empties = List.mapPartial (fn (nm, (CRecord [], _)) => + SOME nm + | _ => NONE) tabs in - (map (fn (nm, c) => (nm, + (empties, + map (fn (nm, c) => (nm, (CTuple [c, (CWild (KRecord (KType, loc), loc), loc)], loc))) tabs, @@ -1494,6 +1500,9 @@ end val e = (EVar (["Basis"], "sql_query1", Infer), loc) + val e = (ECApp (e, (CRecord (map (fn nm => (nm, (CUnit, loc))) empties), + loc)), loc) + val e = (EDisjointApp e, loc) val re = (ERecord [((CName "Distinct", loc), dopt), ((CName "From", loc), @@ -1517,6 +1526,7 @@ | query1 UNION query1 (sql_relop ("union", query11, query12, s (query11left, query12right))) | query1 INTERSECT query1 (sql_relop ("intersect", query11, query12, s (query11left, query12right))) | query1 EXCEPT query1 (sql_relop ("except", query11, query12, s (query11left, query12right))) + | LBRACE LBRACE LBRACE eexp RBRACE RBRACE RBRACE (eexp) tables : fitem (fitem) | fitem COMMA tables (let