From 4759d4381f5cc367b18ae91e341f9bf7da341f7f Mon Sep 17 00:00:00 2001 From: Moritz Heidkamp Date: Fri, 26 Aug 2011 14:15:56 +0200 Subject: [PATCH] add GROUP BY support --- ssql.scm | 3 ++- tests/ansi-test.scm | 9 ++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/ssql.scm b/ssql.scm index ac33c8a..761646b 100644 --- a/ssql.scm +++ b/ssql.scm @@ -48,7 +48,7 @@ (,number? . number->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) (string-translate* string '(("'" . "''")))) @@ -208,6 +208,7 @@ (from prefix "FROM" ", ") (values prefix "VALUES" ", ") (where prefix) + (group prefix "GROUP BY" ", ") (order prefix "ORDER BY" ", ") (having prefix) (union infix) diff --git a/tests/ansi-test.scm b/tests/ansi-test.scm index 7870f30..8ccdefc 100644 --- a/tests/ansi-test.scm +++ b/tests/ansi-test.scm @@ -25,7 +25,14 @@ (test "order" "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 "simple case"