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)) (let ((ssql-op (first op))
(type (second 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)) (error "unknown operator syntax type" type))
(let-optionals (cddr op) (let-optionals (cddr op)
@ -86,11 +86,15 @@
((operator->sql type operator separator operands) ((operator->sql type operator separator operands)
(case type (case type
((infix) ((infix)
(sprintf "(~A)" (string-intersperse (sprintf "(~A)" (self 'operator->sql 'infix* operator separator operands)))
(map (lambda (operand)
(self 'ssql->sql operand)) ((infix*)
operands) (string-intersperse
(string-append " " operator " ")))) (map (lambda (operand)
(self 'ssql->sql operand))
operands)
(string-append " " operator " ")))
((function) ((function)
(sprintf "~A(~A)" (sprintf "~A(~A)"
operator operator
@ -138,7 +142,7 @@
(order prefix "ORDER BY" ", ") (order prefix "ORDER BY" ", ")
(having prefix) (having prefix)
(union infix) (union infix)
(as infix) (as infix*)
(asc suffix) (asc suffix)
(desc suffix) (desc suffix)
(on prefix) (on prefix)

@ -7,8 +7,8 @@
(ssql->sql #f `(select (columns actors.firstname actors.lastname) (ssql->sql #f `(select (columns actors.firstname actors.lastname)
(from actors)))) (from actors))))
(test "Many columns" (test "Many columns"
"SELECT actors.id, actors.firstname, actors.lastname, roles.character, roles.movie_id FROM actors, roles" "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 movie_id)) (ssql->sql #f `(select (columns (col actors id firstname lastname) (col roles character (as movie_id movie)))
(from actors roles)))) (from actors roles))))
(test "Joined query" (test "Joined query"
(string-append (string-append

Loading…
Cancel
Save