diff options
author | Adam Chlipala <adamc@hcoop.net> | 2008-09-07 14:15:16 -0400 |
---|---|---|
committer | Adam Chlipala <adamc@hcoop.net> | 2008-09-07 14:15:16 -0400 |
commit | 95eb24dfa2e3285c3745677acf481fe19b39ee0a (patch) | |
tree | 1aa4c73bb850e6bf55ff3d96acf3bc08213afe23 | |
parent | a034349c535b054c9d31beb4e1133f8cd0b68c5a (diff) |
Parsing UPDATE
-rw-r--r-- | lib/basis.urs | 3 | ||||
-rw-r--r-- | src/urweb.grm | 14 | ||||
-rw-r--r-- | tests/update.ur | 2 |
3 files changed, 17 insertions, 2 deletions
diff --git a/lib/basis.urs b/lib/basis.urs index 13bb1de1..a095a57e 100644 --- a/lib/basis.urs +++ b/lib/basis.urs @@ -210,7 +210,8 @@ val insert : fields ::: {Type} -> dml val update : changed ::: {Type} -> unchanged ::: {Type} -> changed ~ unchanged - -> $changed + -> $(fold (fn nm (t :: Type) acc => [nm] ~ acc => + [nm = sql_exp [T = changed ++ unchanged] [] [] t] ++ acc) [] changed) -> sql_table (changed ++ unchanged) -> sql_exp [T = changed ++ unchanged] [] [] bool -> dml diff --git a/src/urweb.grm b/src/urweb.grm index 1d47f36c..c67035de 100644 --- a/src/urweb.grm +++ b/src/urweb.grm @@ -283,6 +283,7 @@ fun native_op (oper, e1, e2, loc) = | texp of exp | fields of con list | sqlexps of exp list + | fsets of (con * exp) list %verbose (* print summary of errors *) @@ -747,6 +748,16 @@ eterm : LPAREN eexp RPAREN (#1 eexp, s (LPARENleft, RPARENright)) (); (EApp (e, (ERecord (ListPair.zip (fields, sqlexps)), loc)), loc) end) + | LPAREN UPDATE texp SET fsets CWHERE sqlexp RPAREN + (let + val loc = s (LPARENleft, RPARENright) + + val e = (EVar (["Basis"], "update"), loc) + val e = (EApp (e, (ERecord fsets, loc)), loc) + val e = (EApp (e, texp), loc) + in + (EApp (e, sqlexp), loc) + end) | UNDER (EWild, s (UNDERleft, UNDERright)) @@ -759,6 +770,9 @@ fields : fident ([fident]) sqlexps: sqlexp ([sqlexp]) | sqlexp COMMA sqlexps (sqlexp :: sqlexps) +fsets : fident EQ sqlexp ([(fident, sqlexp)]) + | fident EQ sqlexp COMMA fsets ((fident, sqlexp) :: fsets) + idents : ident ([ident]) | ident DOT idents (ident :: idents) diff --git a/tests/update.ur b/tests/update.ur index 25efa348..e58c10cb 100644 --- a/tests/update.ur +++ b/tests/update.ur @@ -1,5 +1,5 @@ table t1 : {A : int, B : string, C : float, D : bool} fun main () : transaction page = - () <- dml (update {B = "6", C = 7.0} t1 (WHERE T.A = 5)); + () <- dml (UPDATE t1 SET B = '6', C = 7.0 WHERE T.A = 5); return <html><body>Updated.</body></html> |