change insert syntax

master
Moritz Heidkamp 13 years ago
parent b2a6da33c2
commit d1de827a00

@ -56,16 +56,24 @@
((pair->sql pair)
(self (car pair) (cdr pair)))
((values vals)
((list->sql-tuple list)
(sprintf "(~A)"
(string-intersperse
(map (lambda (s)
(self 'ssql->sql s #t))
vals)
list)
", ")))
((values records)
(sprintf "VALUES ~A"
(string-intersperse
(map (lambda (record)
(self 'list->sql-tuple record))
records)
", ")))
((vector->sql vec)
(self 'values (vector->list vec)))
(self 'list->sql-tuple (vector->list vec)))
((string->sql string)
(string-append "'" (self 'escape-string string) "'"))
@ -100,29 +108,31 @@
((set values)
(string-append "SET "
(string-intersperse (map (lambda (val)
(string-intersperse
(map (lambda (val)
(sprintf "~A = ~A"
(first val)
(self 'ssql->sql (second val))))
values)
", ")))
((insert into values)
(sprintf "INSERT INTO ~A VALUES ~A"
((insert into rest)
(sprintf "INSERT INTO ~A ~A"
into
(string-intersperse (map (lambda (val)
(self 'ssql->sql val))
values) ", ")))
(string-intersperse
(map (lambda (s)
(self 'ssql->sql s))
rest))))
((insert (('into table) ('columns columns ...) values ...))
((insert (('into table) ('columns columns ...) rest ...))
(self 'insert
(sprintf "~A (~A)"
table
(string-intersperse (map symbol->string columns) ", "))
values))
rest))
((insert (('into table) values ...))
(self 'insert table values))
((insert (('into table) rest ...))
(self 'insert table rest))
((operator->sql type operator separator operands)
(case type

@ -39,19 +39,23 @@
(test-group "inserts"
(test "with sub-queries"
"INSERT INTO roles (character, movie_id, actor_id) VALUES ('Dr. Hasenbein', (SELECT id FROM movies WHERE (title = 'Praxis Dr. Hasenbein')), (SELECT id FROM actors WHERE ((firstname = 'Helge') AND (lastname = 'Schneider'))))"
(ssql->sql #f '(insert (into roles) (columns character movie_id actor_id)
(values "Dr. Hasenbein"
(ssql->sql #f '(insert (into roles)
(columns character movie_id actor_id)
(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 using vectors for the records"
"INSERT INTO actors (firstname, lastname) VALUES ('Sylvester', 'Stallone'), ('Arnold', 'Schwarzenegger')"
(ssql->sql #f '(insert (into actors) (columns firstname lastname) #("Sylvester" "Stallone") #("Arnold" "Schwarzenegger"))))
(ssql->sql #f '(insert (into actors)
(columns firstname lastname)
(values ("Sylvester" "Stallone")
("Arnold" "Schwarzenegger")))))
(test "without explicit columns"
"INSERT INTO actors VALUES ('Marlon', 'Brando')"
(ssql->sql #f '(insert (into actors) (values "Marlon" "Brando")))))
(ssql->sql #f '(insert (into actors) (values ("Marlon" "Brando"))))))
(test-group "syntax"
(test "set literals"

Loading…
Cancel
Save