From 52c0ae01d86d575565db9927b5e9f3846a08b0b5 Mon Sep 17 00:00:00 2001 From: Arnold Noronha Date: Fri, 4 Sep 2020 23:11:51 -0700 Subject: [PATCH] Give WITH-TRANSACTION a convenience return-value --- sql/transaction.lisp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/sql/transaction.lisp b/sql/transaction.lisp index 24465d17..f6addfa7 100644 --- a/sql/transaction.lisp +++ b/sql/transaction.lisp @@ -98,14 +98,17 @@ is called on DATABASE which defaults to *DEFAULT-DATABASE*." which is *DEFAULT-DATABASE* by default, and executes BODY within that transaction. If BODY aborts or throws, DATABASE is rolled back and otherwise the transaction is committed." - (let ((db (gensym "db-"))) - `(let ((,db ,database)) + (let ((db (gensym "db-")) + (ret (gensym "ret-"))) + `(let ((,db ,database) + ,ret) (unwind-protect (prog2 (database-start-transaction ,db) - (progn - ,@body) - (mark-transaction-committed ,db)) + (setf ,ret (progn + ,@body)) + (mark-transaction-committed ,db) + ,ret) (if (eq (transaction-status (transaction ,db)) :committed) (database-commit-transaction ,db) (database-abort-transaction ,db)))))) @@ -149,4 +152,3 @@ Autocommit is turned on by default." (setf (database-autocommit database) value) (database-autocommit database) old-value)) -