From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Nicolas Graves via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#65274: 29.0.91; [feature request] Readonly argument for emacs built-in sqlite support. Date: Wed, 16 Aug 2023 12:17:00 +0200 Message-ID: <87wmxvl2ar.fsf@ngraves.fr> References: <878rbc1eem.fsf@ngraves.fr> <875y5iznne.fsf@ngraves.fr> <83350lbmre.fsf@gnu.org> Reply-To: Nicolas Graves Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="12612"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 65274@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Aug 16 12:18:26 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 1qWDbd-00036u-M6 for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 16 Aug 2023 12:18:25 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qWDbI-0006sa-6K; Wed, 16 Aug 2023 06:18:04 -0400 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 1qWDbG-0006sS-Tc for bug-gnu-emacs@gnu.org; Wed, 16 Aug 2023 06:18:03 -0400 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 1qWDbG-0002LC-LD for bug-gnu-emacs@gnu.org; Wed, 16 Aug 2023 06:18:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qWDbG-0007ll-8U for bug-gnu-emacs@gnu.org; Wed, 16 Aug 2023 06:18:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Nicolas Graves Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 16 Aug 2023 10:18:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 65274 X-GNU-PR-Package: emacs Original-Received: via spool by 65274-submit@debbugs.gnu.org id=B65274.169218103029806 (code B ref 65274); Wed, 16 Aug 2023 10:18:02 +0000 Original-Received: (at 65274) by debbugs.gnu.org; 16 Aug 2023 10:17:10 +0000 Original-Received: from localhost ([127.0.0.1]:38902 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qWDaP-0007ke-J3 for submit@debbugs.gnu.org; Wed, 16 Aug 2023 06:17:10 -0400 Original-Received: from 11.mo581.mail-out.ovh.net ([87.98.173.157]:39175) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qWDaJ-0007kS-K4 for 65274@debbugs.gnu.org; Wed, 16 Aug 2023 06:17:06 -0400 Original-Received: from director3.ghost.mail-out.ovh.net (unknown [10.109.138.157]) by mo581.mail-out.ovh.net (Postfix) with ESMTP id EF7D3257D4 for <65274@debbugs.gnu.org>; Wed, 16 Aug 2023 10:17:01 +0000 (UTC) Original-Received: from ghost-submission-6684bf9d7b-wrkr2 (unknown [10.110.115.64]) by director3.ghost.mail-out.ovh.net (Postfix) with ESMTPS id 71C321FE70; Wed, 16 Aug 2023 10:17:01 +0000 (UTC) Original-Received: from ngraves.fr ([37.59.142.97]) by ghost-submission-6684bf9d7b-wrkr2 with ESMTPSA id uLk7GB2i3GRnQgAA6fNsrw (envelope-from ); Wed, 16 Aug 2023 10:17:01 +0000 Authentication-Results: garm.ovh; auth=pass (GARM-97G0029b08823b-e18b-4ec2-9c17-2e72707f31f0, EFC9AD881B11E31D841027839B6E0A93490164A7) smtp.auth=ngraves@ngraves.fr X-OVh-ClientIp: 81.67.140.142 In-Reply-To: <83350lbmre.fsf@gnu.org> X-Ovh-Tracer-Id: 11681493012382343856 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedviedruddtledgvdeiucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecuhedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefujghffffkgggtsehttdertddttddtnecuhfhrohhmpefpihgtohhlrghsucfirhgrvhgvshcuoehnghhrrghvvghssehnghhrrghvvghsrdhfrheqnecuggftrfgrthhtvghrnhepteehjefhueeileefleeggeffveegheduuddufeeftddvvefhfeffhfdvudehteetnecuffhomhgrihhnpehsrhdrhhhtpdhsthgrtghkohhvvghrfhhlohifrdgtohhmnecukfhppeduvdejrddtrddtrddupdekuddrieejrddugedtrddugedvpdefjedrheelrddugedvrdeljeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeduvdejrddtrddtrddupdhmrghilhhfrhhomhepoehnghhrrghvvghssehnghhrrghvvghsrdhfrheqpdhnsggprhgtphhtthhopedupdhrtghpthhtohepieehvdejgeesuggvsggsuhhgshdrghhnuhdrohhrghdpoffvtefjohhsthep mhhoheekuddpmhhouggvpehsmhhtphhouhht 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:267565 Archived-At: On 2023-08-14 19:40, Eli Zaretskii wrote: >> Date: Sun, 13 Aug 2023 22:35:17 +0200 >> From: Nicolas Graves via "Bug reports for GNU Emacs, >> the Swiss army knife of text editors" >> >> >> The sqlite3 cli tool has an option -readonly, which doesn't seem to be >> available in Emacs for now. This means that if someone wants to inspect >> a locked database, we would necessarily need to make a copy, while the >> -readonly flag would be enough using a shell-command. > > Could you please explain what is a "locked database"? > > The sqlite3 documentation says: > > SQLITE_OPEN_READWRITE > The database is opened for reading and writing if possible, or > reading only if the file is write protected by the operating > system. In either case the database must already exist, otherwise > an error is returned. For historical reasons, if opening in > read-write mode fails due to OS-level permissions, an attempt is > made to open it in read-only mode. sqlite3_db_readonly() can be > used to determine whether the database is actually read-write. > > My interpretation of this is that if opening for reading and writing > fails, SQlite will automatically attempt to open in read-only mode. > Does this not work in some cases? IOW, in which cases would this > readonly option you are asking to add be useful? > > Thanks. I'm sorry, I've resent this unsent patch from July which is rather not precise, I now have more information. My use-case is the package ibrowse.el, which uses sql commands to parse in real time the database of browser (for history or bookmarks, depending on the case) (https://git.sr.ht/~ngraves/ibrowse.el/tree/master/item/ibrowse-sql.el). Web browsers use very frequent updates and most of the time, even trying to access it with readonly mode is not enough (I don't remember all the details, but it's something along the lines of you can't open even in read-only mode if the database file is currently being updated). Most other emacs packages which try to do the same thing circumvent the issue by copying the whole database to /tmp and parsing it from there. I've found another solution which doesn't require to copy the file and it's to open it in immutable mode (https://git.sr.ht/~ngraves/ibrowse.el/tree/master/item/ibrowse-sql.el#L58) I remember the following stackoverflow link lead me to try this: https://stackoverflow.com/questions/7857755/is-it-possible-to-open-a-locked-sqlite-database-in-read-only-mode On the CLI, it's simply done by adding the uri file:...?immutable=1. The SQL manual warns for possible errors if the database is being updated at the same time, but I don't keep an open connection so I don't experience any error whatsoever. One stackoverflow comment also hints about how it could be done, this probably applies to emacs as well: "To achieve the same thing with most SQLite drivers, because we can't directly set SQLITE_IOCAP_IMMUTABLE, the best way is to open the connection with the flag SQLITE_OPEN_READONLY | SQLITE_OPEN_URI to allow passing the file:...?immutable=1 URI as filename." I've verified that this cannot be done on my version of emacs+sqlite (currently GNU Emacs 29.0.92 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.37, cairo version 1.16.0)). I know this is not the recommended way to use the sqlite builtin-support (not a database by/for emacs, but parsing another app data), but I would greatly appreciate if I can use this option with the builtin support. Thanks a lot for your work on emacs, -- Best regards, Nicolas Graves