aboutsummaryrefslogtreecommitdiffstats
path: root/src/sqlite.c
diff options
context:
space:
mode:
authorEli Zaretskii2021-12-11 11:54:44 +0200
committerEli Zaretskii2021-12-11 11:54:44 +0200
commit4cdc59f33a0759a238184e67d59ea8e5143b7cc2 (patch)
tree3d037ada9e0b2d2ee7e9ce37bb64fa656bb0810a /src/sqlite.c
parent628306c299923551cdc8cf09c874744ae7b74216 (diff)
downloademacs-4cdc59f33a0759a238184e67d59ea8e5143b7cc2.tar.gz
emacs-4cdc59f33a0759a238184e67d59ea8e5143b7cc2.zip
Minor cleanups in sqlite.c
* src/sqlite.c (Fsqlite_open): Signal an error if 'init_sqlite_functions' fails. Encode FILE using UTF-8. (Fsqlite_close, Fsqlite_execute, Fsqlite_select) (Fsqlite_load_extension): Doc fixes. (Fsqlite_load_extension): Encode MODULE using UTF-8.
Diffstat (limited to 'src/sqlite.c')
-rw-r--r--src/sqlite.c28
1 files changed, 16 insertions, 12 deletions
diff --git a/src/sqlite.c b/src/sqlite.c
index 47829cbdf7f..87cebb16860 100644
--- a/src/sqlite.c
+++ b/src/sqlite.c
@@ -241,12 +241,14 @@ If 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 char *name;
244 init_sqlite_functions (); 244 if (!init_sqlite_functions ())
245 xsignal1 (Qerror, build_string ("sqlite support is not available"));
245 246
246 if (!NILP (file)) 247 if (!NILP (file))
247 { 248 {
248 CHECK_STRING (file); 249 CHECK_STRING (file);
249 name = xstrdup (SSDATA (Fexpand_file_name (file, Qnil))); 250 file = encode_string (Fexpand_file_name (file, Qnil));
251 name = xstrdup (SSDATA (file));
250 } 252 }
251 else 253 else
252 /* In-memory database. These have to have different names to 254 /* In-memory database. These have to have different names to
@@ -273,7 +275,7 @@ If FILE is nil, an in-memory database will be opened instead. */)
273} 275}
274 276
275DEFUN ("sqlite-close", Fsqlite_close, Ssqlite_close, 1, 1, 0, 277DEFUN ("sqlite-close", Fsqlite_close, Ssqlite_close, 1, 1, 0,
276 doc: /* Close the database DB. */) 278 doc: /* Close the sqlite database DB. */)
277 (Lisp_Object db) 279 (Lisp_Object db)
278{ 280{
279 check_sqlite (db, false); 281 check_sqlite (db, false);
@@ -341,12 +343,12 @@ bind_values (sqlite3 *db, sqlite3_stmt *stmt, Lisp_Object values)
341 343
342DEFUN ("sqlite-execute", Fsqlite_execute, Ssqlite_execute, 2, 3, 0, 344DEFUN ("sqlite-execute", Fsqlite_execute, Ssqlite_execute, 2, 3, 0,
343 doc: /* Execute a non-select SQL statement. 345 doc: /* Execute a non-select SQL statement.
344If VALUES is non-nil, it should be a list of values to bind when 346If VALUES is non-nil, it should be a vector or a list of values
345executing a statement like 347to bind when executing a statement like
346 348
347 insert into foo values (?, ?, ...) 349 insert into foo values (?, ?, ...)
348 350
349The number of affected rows is returned. */) 351Value is the number of affected rows. */)
350 (Lisp_Object db, Lisp_Object query, Lisp_Object values) 352 (Lisp_Object db, Lisp_Object query, Lisp_Object values)
351{ 353{
352 check_sqlite (db, false); 354 check_sqlite (db, false);
@@ -463,8 +465,8 @@ column_names (sqlite3_stmt *stmt)
463 465
464DEFUN ("sqlite-select", Fsqlite_select, Ssqlite_select, 2, 4, 0, 466DEFUN ("sqlite-select", Fsqlite_select, Ssqlite_select, 2, 4, 0,
465 doc: /* Select data from the database DB that matches QUERY. 467 doc: /* Select data from the database DB that matches QUERY.
466If VALUES is non-nil, they are values that will be interpolated into a 468If VALUES is non-nil, it should be a list or a vector specifying the
467parametrised statement. 469values that will be interpolated into a parameterized statement.
468 470
469By default, the return value is a list where the first element is a 471By default, the return value is a list where the first element is a
470list of column names, and the rest of the elements are the matching data. 472list of column names, and the rest of the elements are the matching data.
@@ -573,16 +575,18 @@ DEFUN ("sqlite-rollback", Fsqlite_rollback, Ssqlite_rollback, 1, 1, 0,
573#ifdef HAVE_SQLITE3_LOAD_EXTENSION 575#ifdef HAVE_SQLITE3_LOAD_EXTENSION
574DEFUN ("sqlite-load-extension", Fsqlite_load_extension, 576DEFUN ("sqlite-load-extension", Fsqlite_load_extension,
575 Ssqlite_load_extension, 2, 2, 0, 577 Ssqlite_load_extension, 2, 2, 0,
576 doc: /* Load an SQlite module into DB. 578 doc: /* Load an SQlite MODULE into DB.
577MODULE should be the file name of an SQlite module .so file. */) 579MODULE should be the name of an SQlite module's file, a
580shared library in the system-dependent format and having a
581system-dependent file-name extension. */)
578 (Lisp_Object db, Lisp_Object module) 582 (Lisp_Object db, Lisp_Object module)
579{ 583{
580 check_sqlite (db, false); 584 check_sqlite (db, false);
581 CHECK_STRING (module); 585 CHECK_STRING (module);
586 Lisp_Object module_encoded = encode_string (Fexpand_file_name (module, Qnil));
582 587
583 sqlite3 *sdb = XSQLITE (db)->db; 588 sqlite3 *sdb = XSQLITE (db)->db;
584 int result = sqlite3_load_extension (sdb, 589 int result = sqlite3_load_extension (sdb, SSDATA (module_encoded),
585 SSDATA (Fexpand_file_name (module, Qnil)),
586 NULL, NULL); 590 NULL, NULL);
587 if (result == SQLITE_OK) 591 if (result == SQLITE_OK)
588 return Qt; 592 return Qt;