ssql: add `infix*' operator type which allows defining infix operators without surrounding parens (required for column aliases with `AS')

master
Moritz Heidkamp 14 years ago
parent 3dcf68e37f
commit 3b59938c32

@ -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)

@ -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

Loading…
Cancel
Save