allow inserts without explicit column list

master
Moritz Heidkamp 13 years ago
parent f0b456f288
commit 8307540474

@ -107,14 +107,23 @@
values) values)
", "))) ", ")))
((insert (('into table) ('columns columns ...) values ...)) ((insert into values)
(sprintf "INSERT INTO ~A (~A) VALUES ~A" (sprintf "INSERT INTO ~A VALUES ~A"
table into
(string-intersperse (map symbol->string columns) ", ")
(string-intersperse (map (lambda (val) (string-intersperse (map (lambda (val)
(self (car val) (cdr val))) (self (car val) (cdr val)))
values) ", "))) 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) ((operator->sql type operator separator operands)
(case type (case type
((infix) ((infix)

@ -43,7 +43,15 @@
(values "Dr. Hasenbein" (values "Dr. Hasenbein"
(select (columns id) (from movies) (where (= title "Praxis Dr. Hasenbein"))) (select (columns id) (from movies) (where (= title "Praxis Dr. Hasenbein")))
(select (columns id) (from actors) (where (and (= firstname "Helge") (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-group "syntax"
(test "set literals" (test "set literals"

Loading…
Cancel
Save