emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 9ce0fe5: Add a new `sqlite-pragma' command


From: Lars Ingebrigtsen
Subject: master 9ce0fe5: Add a new `sqlite-pragma' command
Date: Mon, 13 Dec 2021 00:08:19 -0500 (EST)

branch: master
commit 9ce0fe5ef4d6e9c3dcd69237e0b5bb3fd46ee7da
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    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.
---
 doc/lispref/text.texi | 15 +++++++++++++++
 src/sqlite.c          | 12 ++++++++++++
 2 files changed, 27 insertions(+)

diff --git a/doc/lispref/text.texi b/doc/lispref/text.texi
index b8d92f7..5ab5e57 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
 transaction held, and commits the transaction at the end.
 @end defmac
 
+@defun sqlite-pragma db pragma
+Execute @var{pragma} in @var{db}.  A @dfn{pragma} is usually a command
+that affects the database overall, instead of any particular table.
+For instance, to make SQLite automatically garbage collect data that's
+no longer needed, you can say:
+
+@lisp
+(sqlite-pragma db "auto_vacuum = FULL")
+@end lisp
+
+This function returns non-@code{nil} on success and @code{nil} if the
+pragma failed.  Many pragmas can only be issued when the database is
+brand new and empty.
+@end defun
+
 @defun sqlite-load-extension db module
 Load the named extension @var{module} into the database @var{db}.
 Extensions are usually shared-library files; on GNU and Unix systems,
diff --git a/src/sqlite.c b/src/sqlite.c
index 38e939c..4968ce3 100644
--- a/src/sqlite.c
+++ b/src/sqlite.c
@@ -574,6 +574,17 @@ DEFUN ("sqlite-rollback", Fsqlite_rollback, 
Ssqlite_rollback, 1, 1, 0,
   return sqlite_exec (XSQLITE (db)->db, "rollback");
 }
 
+DEFUN ("sqlite-pragma", Fsqlite_pragma, Ssqlite_pragma, 2, 2, 0,
+       doc: /* Execute PRAGMA in DB.  */)
+  (Lisp_Object db, Lisp_Object pragma)
+{
+  check_sqlite (db, false);
+  CHECK_STRING (pragma);
+
+  return sqlite_exec (XSQLITE (db)->db,
+                     SSDATA (concat2 (build_string ("PRAGMA "), pragma)));
+}
+
 #ifdef HAVE_SQLITE3_LOAD_EXTENSION
 DEFUN ("sqlite-load-extension", Fsqlite_load_extension,
        Ssqlite_load_extension, 2, 2, 0,
@@ -689,6 +700,7 @@ syms_of_sqlite (void)
   defsubr (&Ssqlite_transaction);
   defsubr (&Ssqlite_commit);
   defsubr (&Ssqlite_rollback);
+  defsubr (&Ssqlite_pragma);
 #ifdef HAVE_SQLITE3_LOAD_EXTENSION
   defsubr (&Ssqlite_load_extension);
 #endif



reply via email to

[Prev in Thread] Current Thread [Next in Thread]