From 1e99b02fe12a46eee68b8a58c48c6f426393e0d3 Mon Sep 17 00:00:00 2001 From: Eitaro Fukamachi Date: Fri, 9 Aug 2024 07:07:26 +0000 Subject: [PATCH] Make `do-select` work even with `select-by-sql`. --- README.markdown | 2 ++ src/core/dao.lisp | 22 ++++++++++++---------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/README.markdown b/README.markdown index d5930a0..77aeff9 100644 --- a/README.markdown +++ b/README.markdown @@ -626,6 +626,8 @@ Since `insert-dao`, `update-dao` and `delete-dao` are defined as generic functio do (return dao)) ``` +The query form must be one of `select-dao`, `retrieve-dao`, or `select-by-sql`. + ## Installation ```common-lisp diff --git a/src/core/dao.lisp b/src/core/dao.lisp index 3d14cca..4c66cdb 100644 --- a/src/core/dao.lisp +++ b/src/core/dao.lisp @@ -230,13 +230,16 @@ collect value))))) (defun select-by-sql (class sql &key binds) - (mapcar (lambda (result) - (apply #'make-dao-instance class result)) - (retrieve-by-sql sql :binds binds))) + (if *want-cursor* + (select-by-sql-as-cursor class sql :binds binds) + (mapcar (lambda (result) + (apply #'make-dao-instance class result)) + (retrieve-by-sql sql :binds binds)))) (defun include-foreign-objects (foreign-class records) (when records - (let ((foreign-class (ensure-class foreign-class))) + (let ((*want-cursor* nil) + (foreign-class (ensure-class foreign-class))) (when (cdr (table-primary-key foreign-class)) (error "Cannot use 'includes' with a class which has composite primary keys.")) (let* ((class (class-of (first records))) @@ -360,12 +363,11 @@ (dolist (,clause (list ,@clauses)) (when ,clause (add-child ,sql ,clause))) - (if *want-cursor* - (select-by-sql-as-cursor ,class ,sql) - (let ((,results (select-by-sql ,class ,sql))) - (dolist (,foreign-class (remove-duplicates ,include-classes)) - (include-foreign-objects ,foreign-class ,results)) - (values ,results ,sql))))))))))) + (let ((,results (select-by-sql ,class ,sql))) + (unless *want-cursor* + (dolist (,foreign-class (remove-duplicates ,include-classes)) + (include-foreign-objects ,foreign-class ,results))) + (values ,results ,sql)))))))))) (defun where-and (fields-and-values class) (when fields-and-values