From 3b59938c32811ecc240179712365d7a067709323 Mon Sep 17 00:00:00 2001 From: Moritz Heidkamp Date: Thu, 31 Mar 2011 21:03:22 +0200 Subject: [PATCH] ssql: add `infix*' operator type which allows defining infix operators without surrounding parens (required for column aliases with `AS') --- ssql.scm | 18 +++++++++++------- tests/ansi-test.scm | 4 ++-- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/ssql.scm b/ssql.scm index 3dbbd49..10e5b3f 100644 --- a/ssql.scm +++ b/ssql.scm @@ -26,7 +26,7 @@ (let ((ssql-op (first op)) (type (second op))) - (unless (memq (strip-syntax type) '(infix suffix prefix function)) + (unless (memq (strip-syntax type) '(infix infix* suffix prefix function)) (error "unknown operator syntax type" type)) (let-optionals (cddr op) @@ -86,11 +86,15 @@ ((operator->sql type operator separator operands) (case type ((infix) - (sprintf "(~A)" (string-intersperse - (map (lambda (operand) - (self 'ssql->sql operand)) - operands) - (string-append " " operator " ")))) + (sprintf "(~A)" (self 'operator->sql 'infix* operator separator operands))) + + ((infix*) + (string-intersperse + (map (lambda (operand) + (self 'ssql->sql operand)) + operands) + (string-append " " operator " "))) + ((function) (sprintf "~A(~A)" operator @@ -138,7 +142,7 @@ (order prefix "ORDER BY" ", ") (having prefix) (union infix) - (as infix) + (as infix*) (asc suffix) (desc suffix) (on prefix) diff --git a/tests/ansi-test.scm b/tests/ansi-test.scm index 4c6dad3..adc00a9 100644 --- a/tests/ansi-test.scm +++ b/tests/ansi-test.scm @@ -7,8 +7,8 @@ (ssql->sql #f `(select (columns actors.firstname actors.lastname) (from actors)))) (test "Many columns" - "SELECT actors.id, actors.firstname, actors.lastname, roles.character, roles.movie_id FROM actors, roles" - (ssql->sql #f `(select (columns (col actors id firstname lastname) (col roles character movie_id)) + "SELECT actors.id, actors.firstname, actors.lastname, roles.character, roles.movie_id AS movie FROM actors, roles" + (ssql->sql #f `(select (columns (col actors id firstname lastname) (col roles character (as movie_id movie))) (from actors roles)))) (test "Joined query" (string-append