add GROUP BY support

master
Moritz Heidkamp 13 years ago
parent 976718ed55
commit 4759d4381f

@ -48,7 +48,7 @@
(,number? . number->sql) (,number? . number->sql)
(,vector? . vector->sql))) (,vector? . vector->sql)))
((clauses-order) '(columns from table into set values where order having union)) ((clauses-order) '(columns from table into set values where group having order union))
((escape-string string) ((escape-string string)
(string-translate* string '(("'" . "''")))) (string-translate* string '(("'" . "''"))))
@ -208,6 +208,7 @@
(from prefix "FROM" ", ") (from prefix "FROM" ", ")
(values prefix "VALUES" ", ") (values prefix "VALUES" ", ")
(where prefix) (where prefix)
(group prefix "GROUP BY" ", ")
(order prefix "ORDER BY" ", ") (order prefix "ORDER BY" ", ")
(having prefix) (having prefix)
(union infix) (union infix)

@ -25,7 +25,14 @@
(test "order" (test "order"
"SELECT lastname, firstname FROM people ORDER BY lastname DESC, firstname" "SELECT lastname, firstname FROM people ORDER BY lastname DESC, firstname"
(ssql->sql #f '(select (columns lastname firstname) (from people) (order (desc lastname) firstname))))) (ssql->sql #f '(select (columns lastname firstname) (from people) (order (desc lastname) firstname))))
(test "group"
"SELECT actors.name, COUNT(roles.id) FROM roles, actors WHERE (roles.actor_id = actors.id) GROUP BY actors.name"
(ssql->sql #f '(select (columns (col actors name) (count (col roles id)))
(from roles actors)
(where (= (col roles actor_id) (col actors id)))
(group (col actors name))))))
(test-group "updates" (test-group "updates"
(test "simple case" (test "simple case"

Loading…
Cancel
Save