with-transaction
"Eduardo Muñoz" <[email protected]> 19 Apr 2003 23:07:04 +0200
| Newsgroups | gmane.lisp.uncommon-sql |
|---|---|
| Organization | Not likely |
| Message-ID | <[email protected]> |
Currently the 'with-transaction' macro always returns nil
for a successful transaction. I propose the following
modification that will return the values resulting from the
evaluation of body.
I'm posting the whole thing instead of a diff. BTW,
yesterday diffs are against uncommonsql-1.16 (Debian
stable).
(defmacro with-transaction ((&key database)
&rest body)
(let ((dbsym (gensym "db"))
(transym (gensym "tran")))
`(let ((,dbsym (or ,database *default-database*))
(,transym t)
(*transaction-id* (or *transaction-id*
(gensym "txn")))
(*transaction-level* (1+ *transaction-level*)))
(unwind-protect
(progn
(database-start-transaction ,dbsym)
(multiple-value-prog1
(progn ,@body)
(database-commit-transaction ,dbsym)
(setf ,transym nil)))
(if ,transym
(progn ; was aborted
(database-abort-transaction ,dbsym)
;; (format t "~&;; Transaction Abort, level ~d~%" *transaction-level*)
(run-abort-hooks)
(when (= 1 *transaction-level*)
(remhash *transaction-id* *transaction-aborts*)))
(when (= 1 *transaction-level*)
(let ((completes (gethash *transaction-id* *transaction-completes*)))
;; (format t "~&;; Running ~d post actions.~%" (length completes))
(mapcar #'funcall completes)
(remhash *transaction-id* *transaction-completes*))))))))
--
Eduardo Muñoz | (prog () 10 (print "Hello world!")
http://213.97.131.125/ | 20 (go 10))