diff options
| author | Eli Zaretskii | 2021-12-11 11:54:44 +0200 |
|---|---|---|
| committer | Eli Zaretskii | 2021-12-11 11:54:44 +0200 |
| commit | 4cdc59f33a0759a238184e67d59ea8e5143b7cc2 (patch) | |
| tree | 3d037ada9e0b2d2ee7e9ce37bb64fa656bb0810a /src/sqlite.c | |
| parent | 628306c299923551cdc8cf09c874744ae7b74216 (diff) | |
| download | emacs-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.c | 28 |
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 | ||
| 275 | DEFUN ("sqlite-close", Fsqlite_close, Ssqlite_close, 1, 1, 0, | 277 | DEFUN ("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 | ||
| 342 | DEFUN ("sqlite-execute", Fsqlite_execute, Ssqlite_execute, 2, 3, 0, | 344 | DEFUN ("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. |
| 344 | If VALUES is non-nil, it should be a list of values to bind when | 346 | If VALUES is non-nil, it should be a vector or a list of values |
| 345 | executing a statement like | 347 | to bind when executing a statement like |
| 346 | 348 | ||
| 347 | insert into foo values (?, ?, ...) | 349 | insert into foo values (?, ?, ...) |
| 348 | 350 | ||
| 349 | The number of affected rows is returned. */) | 351 | Value 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 | ||
| 464 | DEFUN ("sqlite-select", Fsqlite_select, Ssqlite_select, 2, 4, 0, | 466 | DEFUN ("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. |
| 466 | If VALUES is non-nil, they are values that will be interpolated into a | 468 | If VALUES is non-nil, it should be a list or a vector specifying the |
| 467 | parametrised statement. | 469 | values that will be interpolated into a parameterized statement. |
| 468 | 470 | ||
| 469 | By default, the return value is a list where the first element is a | 471 | By default, the return value is a list where the first element is a |
| 470 | list of column names, and the rest of the elements are the matching data. | 472 | list 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 |
| 574 | DEFUN ("sqlite-load-extension", Fsqlite_load_extension, | 576 | DEFUN ("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. |
| 577 | MODULE should be the file name of an SQlite module .so file. */) | 579 | MODULE should be the name of an SQlite module's file, a |
| 580 | shared library in the system-dependent format and having a | ||
| 581 | system-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; |