Function: sqlite-open

sqlite-open is a function defined in sqlite.c.

Signature

(sqlite-open &optional FILE READONLY DISABLE-URI)

Documentation

Open FILE as an sqlite database.

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.

View in manual

Probably introduced at or before Emacs version 31.1.

Source Code

// Defined in /usr/src/emacs/src/sqlite.c
{
  Lisp_Object name;
  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
  if (NILP (disable_uri))
    flags |= SQLITE_OPEN_URI;
#endif

  if (!init_sqlite_functions ())
    xsignal1 (Qsqlite_error, build_string ("sqlite support is not available"));

  if (!NILP (file))
    name = ENCODE_FILE (Fexpand_file_name (file, Qnil));
  else
    {
#ifdef SQLITE_OPEN_MEMORY
      /* In-memory database.  These have to have different names to
	 refer to different databases.  */
      AUTO_STRING (memory_fmt, ":memory:%d");
      name = CALLN (Fformat, memory_fmt, make_int (++db_count));
      flags |= SQLITE_OPEN_MEMORY;
#else
      xsignal1 (Qsqlite_error, build_string ("sqlite in-memory is not available"));
#endif
    }

  sqlite3 *sdb;
  if (sqlite3_open_v2 (SSDATA (name), &sdb, flags, NULL) != SQLITE_OK)
    return Qnil;

  return make_sqlite (false, sdb, NULL, xstrdup (SSDATA (name)));
}