diff --git a/ssql.scm b/ssql.scm index 24953cb..a9af980 100644 --- a/ssql.scm +++ b/ssql.scm @@ -94,6 +94,15 @@ (string-upcase (symbol->string type)) (string-join (map (lambda (x) (self 'ssql->sql x)) rest)))))) + ((set values) + (string-append "SET " + (string-intersperse (map (lambda (val) + (sprintf "~A = ~A" + (first val) + (self 'ssql->sql (second val)))) + values) + ", "))) + ((operator->sql type operator separator operands) (case type ((infix) @@ -148,6 +157,7 @@ (define-operators *ansi-translator* (select prefix) + (update prefix) (from prefix "FROM" ", ") (where prefix) (order prefix "ORDER BY" ", ") diff --git a/tests/ansi-test.scm b/tests/ansi-test.scm index 72ea54b..a6ef650 100644 --- a/tests/ansi-test.scm +++ b/tests/ansi-test.scm @@ -27,6 +27,15 @@ "SELECT lastname, firstname FROM people ORDER BY lastname DESC, firstname" (ssql->sql #f '(select (columns lastname firstname) (from people) (order (desc lastname) firstname))))) +(test-group "updates" + (test "simple case" + "UPDATE actors SET firstname = 'Rube', lastname = 'Goldberg'" + (ssql->sql #f '(update actors (set (firstname "Rube") (lastname "Goldberg"))))) + + (test "with condition" + "UPDATE actors SET firstname = 'Felix' WHERE (lastname = 'Winkelmann')" + (ssql->sql #f '(update actors (set (firstname "Felix")) (where (= lastname "Winkelmann")))))) + (test-group "syntax" (test "set literals"