From 86ca63c539dddda00f0b6562df9c9838c16bd5a5 Mon Sep 17 00:00:00 2001 From: Moritz Heidkamp Date: Sun, 6 Mar 2011 21:08:44 +0100 Subject: [PATCH] add support for LIMIT, OFFSET and RANDOM() --- ssql-postgresql.scm | 5 +++++ tests/run.scm | 20 ++++++++++++++------ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/ssql-postgresql.scm b/ssql-postgresql.scm index 6ad032a..6de8460 100644 --- a/ssql-postgresql.scm +++ b/ssql-postgresql.scm @@ -19,6 +19,11 @@ ((type->sql-converters) type->sql-converters)))) +(define-operators *postgresql-translator* + (limit prefix) + (offset prefix) + (random function)) + (register-sql-engine! connection? *postgresql-translator*) ) \ No newline at end of file diff --git a/tests/run.scm b/tests/run.scm index ce1fec7..292b992 100644 --- a/tests/run.scm +++ b/tests/run.scm @@ -10,11 +10,19 @@ (register-sql-engine! (lambda (x) (eq? x #t)) *test-postgresql-translator*) -(test-begin "selects") -(test "Simple query" - "SELECT actors.firstname, actors.lastname FROM actors" - (ssql->sql #t `(select (columns actors.firstname actors.lastname) - (from actors)))) -(test-end "selects") +(test-group "selects" + (test "Simple query" + "SELECT actors.firstname, actors.lastname FROM actors" + (ssql->sql #t `(select (columns actors.firstname actors.lastname) + (from actors))))) + +(test-group "dialect" + (test "LIMIT and OFFSET" + "SELECT * FROM integers LIMIT 10 OFFSET 10" + (ssql->sql #t `(select (columns *) (from integers) (limit 10) (offset 100)))) + + (test "random()" + "SELECT * FROM widgets ORDER BY RANDOM()" + (ssql->sql #t `(select (columns *) (from widgets) (order (random)))))) (test-exit) \ No newline at end of file