diff --git a/README.markdown b/README.markdown index 3c16b97..0aa019f 100644 --- a/README.markdown +++ b/README.markdown @@ -21,10 +21,10 @@ ;=> #= ?) AND (age < ?)) ORDER BY age DESC [18, 65]> (union-queries * (select (:id :name :sex) (from '(:as animal a)))) -;=> #= ?) AND (age < ?)) ORDER BY age DESC) UNION (SELECT id, name, sex FROM (animal AS a))> +;=> #= ?) AND (age < ?)) ORDER BY age DESC UNION SELECT id, name, sex FROM (animal AS a)> (yield *) -;=> "(SELECT id, name, sex FROM (person AS p) WHERE ((age >= ?) AND (age < ?)) ORDER BY age DESC) UNION (SELECT id, name, sex FROM (animal AS a))" +;=> "SELECT id, name, sex FROM (person AS p) WHERE ((age >= ?) AND (age < ?)) ORDER BY age DESC UNION SELECT id, name, sex FROM (animal AS a)" ; (18 65) ``` @@ -118,7 +118,7 @@ Creates a SELECT query. It takes a field (or a list of fields) and SQL Clauses. (union-queries (select (:name :birthday) (from :fulltime)) (select (:name :birthday) (from :parttime))) -;=> # +;=> # ``` ### union-all-queries (&rest statements) @@ -127,7 +127,7 @@ Creates a SELECT query. It takes a field (or a list of fields) and SQL Clauses. (union-all-queries (select (:name :birthday) (from :fulltime)) (select (:name :birthday) (from :parttime))) -;=> # +;=> # ``` ### create-table (table column-definitions &body options) diff --git a/src/operator.lisp b/src/operator.lisp index 9634b09..921d0e5 100644 --- a/src/operator.lisp +++ b/src/operator.lisp @@ -245,7 +245,7 @@ case letters." (format nil (if *inside-select* "(~{~A~^ ~})" "~{~A~^ ~}") - (append (list (format nil ,(format nil "~~{(~~A)~~^ ~a ~~}" keyword) + (append (list (format nil ,(format nil "~~{~~A~~^ ~a ~~}" keyword) (mapcar #'yield statements))) (when others (list (format nil "~{~A~^ ~}" diff --git a/t/operator.lisp b/t/operator.lisp index 9fff149..7946d33 100644 --- a/t/operator.lisp +++ b/t/operator.lisp @@ -249,7 +249,7 @@ (select :* (from :table2)) (order-by :column1) (limit 1)))) - (list "(SELECT * FROM `table1`) UNION (SELECT * FROM `table2`) ORDER BY `column1` LIMIT 1" + (list "SELECT * FROM `table1` UNION SELECT * FROM `table2` ORDER BY `column1` LIMIT 1" nil)) (let ((*inside-select* t)) @@ -259,7 +259,7 @@ (select :* (from :table2)) (order-by :column1) (limit 1)))) - (list "((SELECT * FROM `table1`) UNION (SELECT * FROM `table2`) ORDER BY `column1` LIMIT 1)" + (list "(SELECT * FROM `table1` UNION SELECT * FROM `table2` ORDER BY `column1` LIMIT 1)" nil))) (is (multiple-value-list @@ -268,7 +268,7 @@ (select :* (from :table2)) (order-by :column1) (limit 1)))) - (list "(SELECT * FROM `table1`) UNION ALL (SELECT * FROM `table2`) ORDER BY `column1` LIMIT 1" + (list "SELECT * FROM `table1` UNION ALL SELECT * FROM `table2` ORDER BY `column1` LIMIT 1" nil)) (let ((*inside-select* t)) @@ -278,7 +278,7 @@ (select :* (from :table2)) (order-by :column1) (limit 1)))) - (list "((SELECT * FROM `table1`) UNION ALL (SELECT * FROM `table2`) ORDER BY `column1` LIMIT 1)" + (list "(SELECT * FROM `table1` UNION ALL SELECT * FROM `table2` ORDER BY `column1` LIMIT 1)" nil))) (is (multiple-value-list diff --git a/t/statement.lisp b/t/statement.lisp index a39e4fa..425ec4a 100644 --- a/t/statement.lisp +++ b/t/statement.lisp @@ -243,6 +243,6 @@ (make-clause :from (make-sql-symbol "table-2")))))) (ok union-stmt) (is (multiple-value-list (yield union-stmt)) - '("(SELECT * FROM `table-name` WHERE (`age` < ?)) UNION (SELECT * FROM `table-2`)" (20))))) + '("SELECT * FROM `table-name` WHERE (`age` < ?) UNION SELECT * FROM `table-2`" (20))))) (finalize) diff --git a/t/sxql.lisp b/t/sxql.lisp index e8db252..b37900e 100644 --- a/t/sxql.lisp +++ b/t/sxql.lisp @@ -202,14 +202,14 @@ (is-mv (union-queries (select :* (from :table-1) (where (:= :a 10))) (select :* (from :table-2) (where (:> :b 100)))) - '("(SELECT * FROM `table-1` WHERE (`a` = ?)) UNION (SELECT * FROM `table-2` WHERE (`b` > ?))" + '("SELECT * FROM `table-1` WHERE (`a` = ?) UNION SELECT * FROM `table-2` WHERE (`b` > ?)" (10 100)) "UNION") (is-mv (union-all-queries (select :* (from :table-1) (where (:= :a 10))) (select :* (from :table-2) (where (:> :b 100)))) - '("(SELECT * FROM `table-1` WHERE (`a` = ?)) UNION ALL (SELECT * FROM `table-2` WHERE (`b` > ?))" + '("SELECT * FROM `table-1` WHERE (`a` = ?) UNION ALL SELECT * FROM `table-2` WHERE (`b` > ?)" (10 100)) "UNION ALL")