From 830754047479e87d65f58ce4fe95c823271f1c3b Mon Sep 17 00:00:00 2001 From: Moritz Heidkamp Date: Wed, 17 Aug 2011 20:31:01 +0200 Subject: [PATCH] allow inserts without explicit column list --- ssql.scm | 17 +++++++++++++---- tests/ansi-test.scm | 10 +++++++++- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/ssql.scm b/ssql.scm index 3d3b5c4..24d4cff 100644 --- a/ssql.scm +++ b/ssql.scm @@ -107,14 +107,23 @@ values) ", "))) - ((insert (('into table) ('columns columns ...) values ...)) - (sprintf "INSERT INTO ~A (~A) VALUES ~A" - table - (string-intersperse (map symbol->string columns) ", ") + ((insert into values) + (sprintf "INSERT INTO ~A VALUES ~A" + into (string-intersperse (map (lambda (val) (self (car val) (cdr val))) values) ", "))) + ((insert (('into table) ('columns columns ...) values ...)) + (self 'insert + (sprintf "~A (~A)" + table + (string-intersperse (map symbol->string columns) ", ")) + values)) + + ((insert (('into table) values ...)) + (self 'insert table values)) + ((operator->sql type operator separator operands) (case type ((infix) diff --git a/tests/ansi-test.scm b/tests/ansi-test.scm index 4a755f4..cd0a483 100644 --- a/tests/ansi-test.scm +++ b/tests/ansi-test.scm @@ -43,7 +43,15 @@ (values "Dr. Hasenbein" (select (columns id) (from movies) (where (= title "Praxis Dr. Hasenbein"))) (select (columns id) (from actors) (where (and (= firstname "Helge") - (= lastname "Schneider"))))))))) + (= lastname "Schneider")))))))) + + (test "multiple records" + "INSERT INTO actors (firstname, lastname) VALUES ('Sylvester', 'Stallone'), ('Arnold', 'Schwarzenegger')" + (ssql->sql #f '(insert (into actors) (columns firstname lastname) (values "Sylvester" "Stallone") (values "Arnold" "Schwarzenegger")))) + + (test "without explicit columns" + "INSERT INTO actors VALUES ('Marlon', 'Brando')" + (ssql->sql #f '(insert (into actors) (values "Marlon" "Brando"))))) (test-group "syntax" (test "set literals"