aboutsummaryrefslogtreecommitdiffstats
path: root/src/sqlite.c
diff options
context:
space:
mode:
authorPaul Eggert2022-04-17 17:54:25 -0700
committerPaul Eggert2022-04-17 17:55:45 -0700
commit0bb8e127b08dcddc67c7fd62b966d89db5135a79 (patch)
tree3817342c357b0cc838b6c0fd3e348a5a22f86e0e /src/sqlite.c
parent29bf6e64fdad648642a79915d63fe543fdeaff8b (diff)
downloademacs-0bb8e127b08dcddc67c7fd62b966d89db5135a79.tar.gz
emacs-0bb8e127b08dcddc67c7fd62b966d89db5135a79.zip
Port sqlite.c to OS X 10.6.8 with Xcode 3.2.6
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.
Diffstat (limited to 'src/sqlite.c')
-rw-r--r--src/sqlite.c42
1 files 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,
240If FILE is nil, an in-memory database will be opened instead. */) 240If FILE is nil, an in-memory database will be opened instead. */)
241 (Lisp_Object file) 241 (Lisp_Object file)
242{ 242{
243 char *name; 243 Lisp_Object name;
244 int flags = (SQLITE_OPEN_CREATE | SQLITE_OPEN_FULLMUTEX
245 | SQLITE_OPEN_READWRITE);
246#ifdef SQLITE_OPEN_URI
247 flags |= SQLITE_OPEN_URI;
248#endif
249
244 if (!init_sqlite_functions ()) 250 if (!init_sqlite_functions ())
245 xsignal1 (Qerror, build_string ("sqlite support is not available")); 251 xsignal1 (Qerror, build_string ("sqlite support is not available"));
246 252
247 if (!NILP (file)) 253 if (!NILP (file))
254 name = ENCODE_FILE (Fexpand_file_name (file, Qnil));
255 else
248 { 256 {
249 CHECK_STRING (file); 257#ifdef SQLITE_OPEN_MEMORY
250 file = ENCODE_FILE (Fexpand_file_name (file, Qnil)); 258 /* In-memory database. These have to have different names to
251 name = xstrdup (SSDATA (file)); 259 refer to different databases. */
260 AUTO_STRING (memory_fmt, ":memory:%d");
261 name = CALLN (Fformat, memory_fmt, make_int (++db_count));
262 flags |= SQLITE_OPEN_MEMORY;
263#else
264 xsignal1 (Qerror, build_string ("sqlite in-memory is not available"));
265#endif
252 } 266 }
253 else
254 /* In-memory database. These have to have different names to
255 refer to different databases. */
256 name = xstrdup (SSDATA (CALLN (Fformat, build_string (":memory:%d"),
257 make_int (++db_count))));
258 267
259 sqlite3 *sdb; 268 sqlite3 *sdb;
260 int ret = sqlite3_open_v2 (name, 269 if (sqlite3_open_v2 (SSDATA (name), &sdb, flags, NULL) != SQLITE_OK)
261 &sdb,
262 SQLITE_OPEN_FULLMUTEX
263 | SQLITE_OPEN_READWRITE
264 | SQLITE_OPEN_CREATE
265 | (NILP (file) ? SQLITE_OPEN_MEMORY : 0)
266#ifdef SQLITE_OPEN_URI
267 | SQLITE_OPEN_URI
268#endif
269 | 0, NULL);
270
271 if (ret != SQLITE_OK)
272 return Qnil; 270 return Qnil;
273 271
274 return make_sqlite (false, sdb, NULL, name); 272 return make_sqlite (false, sdb, NULL, xstrdup (SSDATA (name)));
275} 273}
276 274
277DEFUN ("sqlite-close", Fsqlite_close, Ssqlite_close, 1, 1, 0, 275DEFUN ("sqlite-close", Fsqlite_close, Ssqlite_close, 1, 1, 0,