From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#67142: 29.1; with-sqlite-transaction commits on exception rather than rolling back Date: Fri, 17 Nov 2023 09:48:41 +0200 Message-ID: <831qcoq0py.fsf@gnu.org> References: <83pm09pz2n.fsf@gnu.org> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="35379"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 67142@debbugs.gnu.org To: Vasilij Schneidermann Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Nov 17 08:49:30 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1r3tbV-0008xT-Re for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 17 Nov 2023 08:49:29 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r3tb7-0002fW-FJ; Fri, 17 Nov 2023 02:49:05 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r3tb4-0002WC-VY for bug-gnu-emacs@gnu.org; Fri, 17 Nov 2023 02:49:03 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r3tb4-0007aA-0j for bug-gnu-emacs@gnu.org; Fri, 17 Nov 2023 02:49:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1r3tb3-0002YB-JG for bug-gnu-emacs@gnu.org; Fri, 17 Nov 2023 02:49:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 17 Nov 2023 07:49:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 67142 X-GNU-PR-Package: emacs Original-Received: via spool by 67142-submit@debbugs.gnu.org id=B67142.17002073399793 (code B ref 67142); Fri, 17 Nov 2023 07:49:01 +0000 Original-Received: (at 67142) by debbugs.gnu.org; 17 Nov 2023 07:48:59 +0000 Original-Received: from localhost ([127.0.0.1]:45034 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r3tb0-0002Xt-IZ for submit@debbugs.gnu.org; Fri, 17 Nov 2023 02:48:58 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:40200) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r3taw-0002XT-7o for 67142@debbugs.gnu.org; Fri, 17 Nov 2023 02:48:57 -0500 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r3taq-000730-7K; Fri, 17 Nov 2023 02:48:48 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=cI367GYTOCUX6mWFnbs5ZMlULqhr8UBdS5fPmnMC0Us=; b=Oi3mPP6u/KHI GwVawa2Wagrp7mxIevRaYFTOi7e0hycZsQN5IX+7N/NSJd5BrMq8WI+RtSKZdbq/xPZr5YInc8znk eU2LoTPNO0J0vugmRHem3ZM2Q8AUPphFT8Nv0cjUHSmsDc/MCqUnnKesUFBSZwyGcos8OJ/ZtvLAj H9jI0m9MhTsXi/iNwiW99R4C1OWe7G3h2dKa9sxJk/aW1g4a9VDnzSiDAWn1bzEEmOUj8qM1FfqVD 0BZeeD0XGGaSumDnuc5Qh4icraj0NrMy36s93U+8A2Wl/mtbfRMehDv5A3Rk1AKeDjeZEKIEVq95P 00ACxjvpGl/v/SFsBXOezQ==; In-Reply-To: (message from Vasilij Schneidermann on Thu, 16 Nov 2023 21:25:53 +0100) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:274490 Archived-At: > Date: Thu, 16 Nov 2023 21:25:53 +0100 > From: Vasilij Schneidermann > Cc: 67142@debbugs.gnu.org > > > Does the change below look correct? (I'm not an expert on SQLite or > > DB programming in general.) > > The `unwind-protect` part does not look correct since the rollback is > always performed, even after the body form completed successfully and a > commit was done. Either a commit or a rollback should be done, not both. Oops. Is the below better? > A minor mistake is the result variable not using an uninterned symbol > (or alternatively, `prog1` could replace the use of the result variable). I don't understand this part, sorry. Why do we need a symbol to return the result of the body? diff --git a/lisp/sqlite.el b/lisp/sqlite.el index aad0aa4..4488896 100644 --- a/lisp/sqlite.el +++ b/lisp/sqlite.el @@ -24,18 +24,25 @@ ;;; 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))) `(let ((,db-var ,db) (,func-var (lambda () ,@body))) (if (sqlite-available-p) - (unwind-protect - (progn - (sqlite-transaction ,db-var) - (funcall ,func-var)) - (sqlite-commit ,db-var)) + (let (result commit) + (unwind-protect + (progn + (sqlite-transaction ,db-var) + (setq result (funcall ,func-var)) + (setq commit (sqlite-commit ,db-var)) + result) + (or commit (sqlite-rollback ,db-var)))) (funcall ,func-var))))) (provide 'sqlite)