From: "J.P." <jp@neverwas.me>
To: Vasilij Schneidermann <mail@vasilij.de>
Cc: Eli Zaretskii <eliz@gnu.org>, visuweshm@gmail.com, 67142@debbugs.gnu.org
Subject: bug#67142: 29.1; with-sqlite-transaction commits on exception rather than rolling back
Date: Sun, 03 Mar 2024 06:04:48 -0800 [thread overview]
Message-ID: <87wmqjtnr3.fsf@neverwas.me> (raw)
In-Reply-To: <ZVvMGBrYUzpjyIsS@odonien.localdomain> (Vasilij Schneidermann's message of "Mon, 20 Nov 2023 22:14:00 +0100")
Vasilij Schneidermann <mail@vasilij.de> writes:
>> OK, how about the below?
>>
>> diff --git a/lisp/sqlite.el b/lisp/sqlite.el
>> index aad0aa4..8a52573 100644
>> --- a/lisp/sqlite.el
>> +++ b/lisp/sqlite.el
>> @@ -24,19 +24,28 @@
>> ;;; Code:
>>
>> (defmacro with-sqlite-transaction (db &rest body)
>> - "Execute BODY while holding a transaction for DB."
>> + "Execute BODY while holding a transaction for DB.
>> +If BODY completes normally, commit the changes and return
>> +the value of BODY.
>> +If BODY signals an error, or transaction commit fails, roll
>> +back the transaction changes."
>> (declare (indent 1) (debug (form body)))
>> (let ((db-var (gensym))
>> - (func-var (gensym)))
>> + (func-var (gensym))
>> + (res-var (gensym))
>> + (commit-var (gensym)))
>> `(let ((,db-var ,db)
>> - (,func-var (lambda () ,@body)))
>> + (,func-var (lambda () ,@body))
>> + ,res-var ,commit-var)
>> (if (sqlite-available-p)
>> (unwind-protect
>> (progn
>> (sqlite-transaction ,db-var)
>> - (funcall ,func-var))
>> - (sqlite-commit ,db-var))
>> - (funcall ,func-var)))))
>> + (setq ,res-var (funcall ,func-var))
>> + (setq ,commit-var (sqlite-commit ,db-var))
>> + ,res-var)
>> + (or ,commit-var (sqlite-rollback ,db-var))))
>> + (funcall ,func-var))))
>>
>> (provide 'sqlite)
>
> Thank you, this looks very good. I've tested it on my own code using the
> SQLite support and there don't appear to be any (obvious issues).
Not obvious on account of the indentation, but it seems the second
(funcall ,func-var)
snuck outside the `if' form with that fix, making body run twice if you
have SQLite.
next prev parent reply other threads:[~2024-03-03 14:04 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-13 0:47 bug#67142: 29.1; with-sqlite-transaction commits on exception rather than rolling back Vasilij Schneidermann
2023-11-16 14:12 ` Eli Zaretskii
2023-11-16 20:25 ` Vasilij Schneidermann
2023-11-17 7:48 ` Eli Zaretskii
2023-11-17 8:38 ` Visuwesh
2023-11-17 9:08 ` Vasilij Schneidermann
2023-11-18 10:37 ` Eli Zaretskii
2023-11-20 21:14 ` Vasilij Schneidermann
2023-11-21 13:39 ` Eli Zaretskii
2024-03-03 14:04 ` J.P. [this message]
2024-03-11 3:43 ` J.P.
2024-03-11 13:25 ` Eli Zaretskii
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87wmqjtnr3.fsf@neverwas.me \
--to=jp@neverwas.me \
--cc=67142@debbugs.gnu.org \
--cc=eliz@gnu.org \
--cc=mail@vasilij.de \
--cc=visuweshm@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.