aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Ingebrigtsen2021-12-13 06:08:09 +0100
committerLars Ingebrigtsen2021-12-13 06:08:09 +0100
commit9ce0fe5ef4d6e9c3dcd69237e0b5bb3fd46ee7da (patch)
treef7fa90b7e601558dc3caa0bb1c46deb88b199b2d
parentc86b86f9a9ee3c42aed9ede794e8c3e19ce35ec5 (diff)
downloademacs-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.texi15
-rw-r--r--src/sqlite.c12
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
5286transaction held, and commits the transaction at the end. 5286transaction held, and commits the transaction at the end.
5287@end defmac 5287@end defmac
5288 5288
5289@defun sqlite-pragma db pragma
5290Execute @var{pragma} in @var{db}. A @dfn{pragma} is usually a command
5291that affects the database overall, instead of any particular table.
5292For instance, to make SQLite automatically garbage collect data that's
5293no longer needed, you can say:
5294
5295@lisp
5296(sqlite-pragma db "auto_vacuum = FULL")
5297@end lisp
5298
5299This function returns non-@code{nil} on success and @code{nil} if the
5300pragma failed. Many pragmas can only be issued when the database is
5301brand new and empty.
5302@end defun
5303
5289@defun sqlite-load-extension db module 5304@defun sqlite-load-extension db module
5290Load the named extension @var{module} into the database @var{db}. 5305Load the named extension @var{module} into the database @var{db}.
5291Extensions are usually shared-library files; on GNU and Unix systems, 5306Extensions 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
577DEFUN ("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
578DEFUN ("sqlite-load-extension", Fsqlite_load_extension, 589DEFUN ("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