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.
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 ())