Support returning multiple values from with-transaction body.
authorAlexander Gavrilov <angavrilov@gmail.com>
Sat, 23 Oct 2010 08:45:42 +0000 (23 12:45 +0400)
committerAlexander Gavrilov <angavrilov@gmail.com>
Sat, 23 Oct 2010 08:45:42 +0000 (23 12:45 +0400)
Multiple-value-prog1 is a special operator designed
specially for cases like this one.

sqlite.lisp

index fcdfbcd..94113e3 100644 (file)
@@ -298,17 +298,14 @@ See BIND-PARAMETER for the list of supported parameter types."
 (defmacro with-transaction (db &body body)
   "Wraps the BODY inside the transaction."
   (let ((ok (gensym "TRANSACTION-COMMIT-"))
-        (db-var (gensym "DB-"))
-        (result (gensym "RESULT-")))
+        (db-var (gensym "DB-")))
     `(let (,ok
            (,db-var ,db))
        (execute-non-query ,db-var "begin transaction")
        (unwind-protect
-            (progn
-              (let ((,result (progn
-                               ,@body)))
-                (setf ,ok t)
-                ,result))
+            (multiple-value-prog1
+                (progn ,@body)
+              (setf ,ok t))
          (if ,ok
              (execute-non-query ,db-var "commit transaction")
              (execute-non-query ,db-var "rollback transaction"))))))