OUTER JOIN
jhyiugjhvbjh234-JGs/[email protected] Mon, 23 Jul 2012 10:09:32 +0400
| Newsgroups | gmane.lisp.clsql.general |
|---|---|
| Message-ID | <[email protected]> |
>Is there any chance to make OUTER JOIN with clsql?
Maybe now it is, but when I started to use clsql I failed to find this
and wrote a small extension to generate such clauses (it is not too
useful to others as it is bound to how my application stores
multipurpose schema).
A simple example of expression generator:
(defclass clsql-wrapper (clsql-sys::%sql-expression)
((content :initarg :content :initform nil :accessor clsql-wrapper-content)
(clsql-sys::name :initarg :name :initform nil)))
(defmethod clsql-sys::output-sql ((self clsql-wrapper) database)
(format clsql-sys::*sql-stream*
"~{~a ~} "
(mapcar (lambda (x)
(progv '(clsql-sys::*sql-stream*) `(,(make-string-output-stream))
(clsql-sys::output-sql x database)
(get-output-stream-string clsql-sys::*sql-stream*)))
(clsql-wrapper-content self))))
(defun sql-wrap (name &rest args)
(make-instance 'clsql-wrapper :content args :name (or name (gensym))))
(defun sql-wrap-list (l)
(apply 'sql-wrap nil l))
(sql-wrap [table1] 'outer 'join [table2] 'on [= [table1 field1] [table2 field2]])