Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
;=> #<SXQL-COMPILED: SELECT id, name, sex FROM person AS p WHERE ((age >= ?) AND (age < ?)) ORDER BY age DESC [18, 65]>

(union-queries * (select (:id :name :sex) (from '(:as animal a))))
;=> #<SXQL-OP: (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))>
;=> #<SXQL-OP: 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)>

(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)
```

Expand Down Expand Up @@ -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)))
;=> #<SXQL-OP: (SELECT name, birthday FROM fulltime) UNION (SELECT name, birthday FROM parttime)>
;=> #<SXQL-OP: SELECT name, birthday FROM fulltime UNION SELECT name, birthday FROM parttime>
```

### union-all-queries (&rest statements)
Expand All @@ -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)))
;=> #<SXQL-OP: (SELECT name, birthday FROM fulltime) UNION ALL (SELECT name, birthday FROM parttime)>
;=> #<SXQL-OP: SELECT name, birthday FROM fulltime UNION ALL SELECT name, birthday FROM parttime>
```

### create-table (table column-definitions &body options)
Expand Down
2 changes: 1 addition & 1 deletion src/operator.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -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~^ ~}"
Expand Down
8 changes: 4 additions & 4 deletions t/operator.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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
Expand All @@ -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))
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion t/statement.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 2 additions & 2 deletions t/sxql.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down