diff options
| author | Lars Ingebrigtsen | 2021-12-13 06:08:09 +0100 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2021-12-13 06:08:09 +0100 |
| commit | 9ce0fe5ef4d6e9c3dcd69237e0b5bb3fd46ee7da (patch) | |
| tree | f7fa90b7e601558dc3caa0bb1c46deb88b199b2d | |
| parent | c86b86f9a9ee3c42aed9ede794e8c3e19ce35ec5 (diff) | |
| download | emacs-9ce0fe5ef4d6e9c3dcd69237e0b5bb3fd46ee7da.tar.gz emacs-9ce0fe5ef4d6e9c3dcd69237e0b5bb3fd46ee7da.zip | |
Add a new `sqlite-pragma' command
* doc/lispref/text.texi (Database): Document it.
* src/sqlite.c (Fsqlite_pragma): Add a separate command for
pragmas. These can be done via sqlite-execute, but it's less
confusing to have them in a separate command.
| -rw-r--r-- | doc/lispref/text.texi | 15 | ||||
| -rw-r--r-- | src/sqlite.c | 12 |
2 files changed, 27 insertions, 0 deletions
diff --git a/doc/lispref/text.texi b/doc/lispref/text.texi index b8d92f7fdca..5ab5e5715f0 100644 --- a/doc/lispref/text.texi +++ b/doc/lispref/text.texi | |||
| @@ -5286,6 +5286,21 @@ Like @code{progn} (@pxref{Sequencing}), but executes @var{body} with a | |||
| 5286 | transaction held, and commits the transaction at the end. | 5286 | transaction held, and commits the transaction at the end. |
| 5287 | @end defmac | 5287 | @end defmac |
| 5288 | 5288 | ||
| 5289 | @defun sqlite-pragma db pragma | ||
| 5290 | Execute @var{pragma} in @var{db}. A @dfn{pragma} is usually a command | ||
| 5291 | that affects the database overall, instead of any particular table. | ||
| 5292 | For instance, to make SQLite automatically garbage collect data that's | ||
| 5293 | no longer needed, you can say: | ||
| 5294 | |||
| 5295 | @lisp | ||
| 5296 | (sqlite-pragma db "auto_vacuum = FULL") | ||
| 5297 | @end lisp | ||
| 5298 | |||
| 5299 | This function returns non-@code{nil} on success and @code{nil} if the | ||
| 5300 | pragma failed. Many pragmas can only be issued when the database is | ||
| 5301 | brand new and empty. | ||
| 5302 | @end defun | ||
| 5303 | |||
| 5289 | @defun sqlite-load-extension db module | 5304 | @defun sqlite-load-extension db module |
| 5290 | Load the named extension @var{module} into the database @var{db}. | 5305 | Load the named extension @var{module} into the database @var{db}. |
| 5291 | Extensions are usually shared-library files; on GNU and Unix systems, | 5306 | Extensions are usually shared-library files; on GNU and Unix systems, |
diff --git a/src/sqlite.c b/src/sqlite.c index 38e939cd84a..4968ce3f690 100644 --- a/src/sqlite.c +++ b/src/sqlite.c | |||
| @@ -574,6 +574,17 @@ DEFUN ("sqlite-rollback", Fsqlite_rollback, Ssqlite_rollback, 1, 1, 0, | |||
| 574 | return sqlite_exec (XSQLITE (db)->db, "rollback"); | 574 | return sqlite_exec (XSQLITE (db)->db, "rollback"); |
| 575 | } | 575 | } |
| 576 | 576 | ||
| 577 | DEFUN ("sqlite-pragma", Fsqlite_pragma, Ssqlite_pragma, 2, 2, 0, | ||
| 578 | doc: /* Execute PRAGMA in DB. */) | ||
| 579 | (Lisp_Object db, Lisp_Object pragma) | ||
| 580 | { | ||
| 581 | check_sqlite (db, false); | ||
| 582 | CHECK_STRING (pragma); | ||
| 583 | |||
| 584 | return sqlite_exec (XSQLITE (db)->db, | ||
| 585 | SSDATA (concat2 (build_string ("PRAGMA "), pragma))); | ||
| 586 | } | ||
| 587 | |||
| 577 | #ifdef HAVE_SQLITE3_LOAD_EXTENSION | 588 | #ifdef HAVE_SQLITE3_LOAD_EXTENSION |
| 578 | DEFUN ("sqlite-load-extension", Fsqlite_load_extension, | 589 | DEFUN ("sqlite-load-extension", Fsqlite_load_extension, |
| 579 | Ssqlite_load_extension, 2, 2, 0, | 590 | Ssqlite_load_extension, 2, 2, 0, |
| @@ -689,6 +700,7 @@ syms_of_sqlite (void) | |||
| 689 | defsubr (&Ssqlite_transaction); | 700 | defsubr (&Ssqlite_transaction); |
| 690 | defsubr (&Ssqlite_commit); | 701 | defsubr (&Ssqlite_commit); |
| 691 | defsubr (&Ssqlite_rollback); | 702 | defsubr (&Ssqlite_rollback); |
| 703 | defsubr (&Ssqlite_pragma); | ||
| 692 | #ifdef HAVE_SQLITE3_LOAD_EXTENSION | 704 | #ifdef HAVE_SQLITE3_LOAD_EXTENSION |
| 693 | defsubr (&Ssqlite_load_extension); | 705 | defsubr (&Ssqlite_load_extension); |
| 694 | #endif | 706 | #endif |