septeql

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit 5b8a4db4b6a3eee871965c342121080cecdcda0d
parent db3f88efe0e86453ce6b173fcbb051b110d60e75
Author: septeql <septeql@telent.net>
Date:   Tue, 21 Oct 2008 20:26:37 +0000

add support for DISTINCT
Diffstat:
Msepteql.lisp | 11+++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/septeql.lisp b/septeql.lisp @@ -114,7 +114,8 @@ interpolated into a SQL statement as a string literal" ;;; this models a sql SELECT statement ;;; XXX we don't support HAVING, mostly becaue I don't understand it (defclass sql () - ((attributes :initarg :attributes) + ((distinct :initarg :distinct) + (attributes :initarg :attributes) (from :initarg :from ) (where :initarg :where) (group-by :initarg :group-by) @@ -173,6 +174,11 @@ interpolated into a SQL statement as a string literal" (setf (sv j 'from) `(left-join ,@(cdr from))) j)) +(define-translator distinct (rel) + (let ((r (parse-relation rel))) + (setf (sv r 'distinct) t) + r)) + (define-translator group (aggregates dividers relation) (let ((l (parse-relation relation))) (when (any-slot-bound-p l '(start end group-by attributes order-by)) @@ -249,7 +255,8 @@ interpolated into a SQL statement as a string literal" (defun as-string (sql) (with-output-to-string (s) - (format s "SELECT ~{~A~^,~} " + (format s "SELECT ~A ~{~A~^,~} " + (if (sv sql 'distinct nil) "DISTINCT" "") (or (mapcar #'translate-scalar (sv sql 'attributes nil)) '(*))) (format s "FROM ~A " (from-clause-as-string (sv sql 'from))) (let* ((nilg (gensym))