Support file:// URIs and readonly DB in 'sqlite-open'

* src/sqlite.c (Fsqlite_open): Two new optional arguments,
READONLY and DISABLE-URI.  Doc fix.

* etc/NEWS:
* doc/lispref/text.texi (Database): Document the new optional
arguments to 'sqlite-open'.  (Bug#65274)
This commit is contained in:
Eli Zaretskii 2025-04-14 12:42:28 +03:00
parent f7ca720e2d
commit 4918de1699
3 changed files with 36 additions and 7 deletions

View file

@ -5366,11 +5366,17 @@ available in this Emacs session.
When SQLite support is available, the following functions can be used.
@cindex database object
@defun sqlite-open &optional file
@defun sqlite-open &optional file readonly disable-uri
This function opens @var{file} as an SQLite database file. If
@var{file} doesn't exist, a new database will be created and stored in
that file. If @var{file} is omitted or @code{nil}, a new in-memory
database is created instead.
database is created instead. Second optional argument @var{readonly},
if non-@code{nil}, means open the database only for reading; the
database must already exist in that case. By default, @var{file} can be
a @file{file://} URI as well as a file name; in the unusual case that
you have a local file whose name begins with @file{file:}, specify a
non-@code{nil} value for the third optional argument @var{disable-uri}
to disable the automatic recognition and processing of URIs.
The return value is a @dfn{database object} that can be used as the
argument to most of the subsequent functions described below.

View file

@ -1895,6 +1895,19 @@ When 'flymake-indicator-type' is set to 'fringes', as is now the default,
flymake will automatically fall back to using margin indicators in
windows without fringes, including any window on a text terminal.
** SQLite
+++
*** SQLite databases can now be opened in read-only mode.
The new optional argument READONLY to 'sqlite-open' function allows to
open an existing database only for reading.
*** 'sqlite-open' now recognizes 'file://' URIs as well as file names.
The 'file://' URIs are supported by default. In the unusual case that a
normal file name starts with "file:", you can disable the URI
recognition by invoking 'sqlite-open' with the new optional argument
DISABLE-URI non-nil.
* New Modes and Packages in Emacs 31.1

View file

@ -277,18 +277,28 @@ 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, 3, 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 or omitted, an in-memory database will be opened instead.
If READONLY is non-nil or omitted, open the database in read-only mode,
otherwise open it in read-write mode.
By default, file:// URIs are automatically recognized, unless
DISABLE-URI is non-nil. */)
(Lisp_Object file, Lisp_Object readonly, Lisp_Object disable_uri)
{
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
#ifdef SQLITE_OPEN_URI
flags |= SQLITE_OPEN_URI;
if (NILP (disable_uri))
flags |= SQLITE_OPEN_URI;
#endif
if (!init_sqlite_functions ())