From 0bb8e127b08dcddc67c7fd62b966d89db5135a79 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sun, 17 Apr 2022 17:54:25 -0700 Subject: [PATCH] Port sqlite.c to OS X 10.6.8 with Xcode 3.2.6 MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Problem reported by Keith David Bershatsky in: https://lists.gnu.org/r/emacs-devel/2022-04/msg00923.html * src/sqlite.c (Fsqlite_open): Don’t assume SQLITE_OPEN_MEMORY is defined. --- src/sqlite.c | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/src/sqlite.c b/src/sqlite.c index 1ca86699318..7388b576e90 100644 --- a/src/sqlite.c +++ b/src/sqlite.c @@ -240,38 +240,36 @@ DEFUN ("sqlite-open", Fsqlite_open, Ssqlite_open, 0, 1, 0, If FILE is nil, an in-memory database will be opened instead. */) (Lisp_Object file) { - char *name; + Lisp_Object name; + int flags = (SQLITE_OPEN_CREATE | SQLITE_OPEN_FULLMUTEX + | SQLITE_OPEN_READWRITE); +#ifdef SQLITE_OPEN_URI + flags |= SQLITE_OPEN_URI; +#endif + if (!init_sqlite_functions ()) xsignal1 (Qerror, build_string ("sqlite support is not available")); if (!NILP (file)) + name = ENCODE_FILE (Fexpand_file_name (file, Qnil)); + else { - CHECK_STRING (file); - file = ENCODE_FILE (Fexpand_file_name (file, Qnil)); - name = xstrdup (SSDATA (file)); +#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 (Qerror, build_string ("sqlite in-memory is not available")); +#endif } - else - /* In-memory database. These have to have different names to - refer to different databases. */ - name = xstrdup (SSDATA (CALLN (Fformat, build_string (":memory:%d"), - make_int (++db_count)))); sqlite3 *sdb; - int ret = sqlite3_open_v2 (name, - &sdb, - SQLITE_OPEN_FULLMUTEX - | SQLITE_OPEN_READWRITE - | SQLITE_OPEN_CREATE - | (NILP (file) ? SQLITE_OPEN_MEMORY : 0) -#ifdef SQLITE_OPEN_URI - | SQLITE_OPEN_URI -#endif - | 0, NULL); - - if (ret != SQLITE_OK) + if (sqlite3_open_v2 (SSDATA (name), &sdb, flags, NULL) != SQLITE_OK) return Qnil; - return make_sqlite (false, sdb, NULL, name); + return make_sqlite (false, sdb, NULL, xstrdup (SSDATA (name))); } DEFUN ("sqlite-close", Fsqlite_close, Ssqlite_close, 1, 1, 0, -- 2.39.2