From b95efc8ca59e317af886f17653f2c2a3c72eeaeb Mon Sep 17 00:00:00 2001 From: Moritz Heidkamp Date: Wed, 17 Aug 2011 19:21:07 +0200 Subject: [PATCH] simple update support --- ssql.scm | 10 ++++++++++ tests/ansi-test.scm | 9 +++++++++ 2 files changed, 19 insertions(+) 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"