bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#65274: 29.0.91; [feature request] Readonly argument for emacs built-


From: Eli Zaretskii
Subject: bug#65274: 29.0.91; [feature request] Readonly argument for emacs built-in sqlite support.
Date: Fri, 15 Sep 2023 09:54:12 +0300

Ping! Ping!

Nicolas, did you perhaps have time to try this patch?

> Cc: 65274@debbugs.gnu.org
> Date: Sat, 02 Sep 2023 10:17:01 +0300
> From: Eli Zaretskii <eliz@gnu.org>
> 
> Ping!  Nicolas, could you please try the patch?  I'd like to install
> it if it solves your problem.
> 
> > Cc: 65274@debbugs.gnu.org
> > Date: Sat, 19 Aug 2023 12:21:05 +0300
> > From: Eli Zaretskii <eliz@gnu.org>
> > 
> > > From: Nicolas Graves <ngraves@ngraves.fr>
> > > Cc: 65274@debbugs.gnu.org
> > > Date: Wed, 16 Aug 2023 12:17:00 +0200
> > > 
> > > 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."
> > 
> > Thanks.  I'm not sure I understood all the intricacies of this use
> > case, but could you please see if the patches below make your use case
> > possible?
> > 
> > diff --git a/src/sqlite.c b/src/sqlite.c
> > index fd528f2..f68edb9 100644
> > --- a/src/sqlite.c
> > +++ b/src/sqlite.c
> > @@ -277,13 +277,20 @@ check_sqlite (Lisp_Object db, bool is_statement)
> >  
> >  static int db_count = 0;
> >  
> > -DEFUN ("sqlite-open", Fsqlite_open, Ssqlite_open, 0, 1, 0,
> > +DEFUN ("sqlite-open", Fsqlite_open, Ssqlite_open, 0, 2, 0,
> >         doc: /* Open FILE as an sqlite database.
> > -If FILE is nil, an in-memory database will be opened instead.  */)
> > -  (Lisp_Object file)
> > +If FILE is nil, an in-memory database will be opened instead.
> > +If READONLY is non-nil, open the database in read-only mode,
> > +otherwise open it in read-write mode.  */)
> > +  (Lisp_Object file, Lisp_Object readonly)
> >  {
> >    Lisp_Object name;
> > -  int flags = (SQLITE_OPEN_CREATE  | SQLITE_OPEN_READWRITE);
> > +  int flags;
> > +
> > +  if (!NILP (readonly))
> > +    flags = SQLITE_OPEN_READONLY;
> > +  else
> > +    flags = (SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE);
> >  #ifdef SQLITE_OPEN_FULLMUTEX
> >    flags |= SQLITE_OPEN_FULLMUTEX;
> >  #endif
> > 
> > 
> > 
> > 
> 
> 
> 
> 





reply via email to

[Prev in Thread] Current Thread [Next in Thread]