]> git.eshelyaron.com Git - emacs.git/commitdiff
Support file:// URIs and readonly DB in 'sqlite-open'
authorEli Zaretskii <eliz@gnu.org>
Mon, 14 Apr 2025 09:42:28 +0000 (12:42 +0300)
committerEshel Yaron <me@eshelyaron.com>
Wed, 16 Apr 2025 07:34:24 +0000 (09:34 +0200)
* 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)

(cherry picked from commit 4918de1699152e98c7aaa3ecb21795a3cbd05194)

doc/lispref/text.texi
src/sqlite.c

index 447b093953edf8b158e3e93d82580435949bfcf0..726a48f1161fa957645d9d3745ac52a391cbdd68 100644 (file)
@@ -5373,11 +5373,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.
index 0de7488d8fdb176ba1096eae5641ed79c7c66f21..99f91fd6da6f21423ea01e9fdd6466df8d79feaa 100644 (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 ())