diff options
author | Lars Ingebrigtsen <larsi@gnus.org> | 2021-12-11 04:55:57 +0100 |
---|---|---|
committer | Lars Ingebrigtsen <larsi@gnus.org> | 2021-12-11 04:55:57 +0100 |
commit | 3d38d1d1345aa65c4018b42e6c648606e32216f8 (patch) | |
tree | 5e6b51f9aa79c6a2e7604934f3ffe9314db21c71 /doc | |
parent | af1c5ec0fcd3f25234cfe2986c873ff2e5ed63a0 (diff) | |
download | emacs-3d38d1d1345aa65c4018b42e6c648606e32216f8.tar.gz |
Add sqlite3 support to Emacs
* configure.ac: Add check for the sqlite library.
* doc/lispref/text.texi (Database): Document it.
* lisp/sqlite.el: New file.
* lisp/term/w32-win.el (dynamic-library-alist): Add a mapping.
* src/Makefile.in (SQLITE3_LIBS): Add the libraries.
* src/alloc.c (union emacs_align_type): Add a Lisp_Sqlite struct.
* src/data.c (Ftype_of): Add sqlite.
* src/emacs.c (main): Load the syms.
* src/lisp.h (DEFINE_GDB_SYMBOL_BEGIN): Add PVEC_SQLITE.
(GCALIGNED_STRUCT): New struct to keep data for sqlite database
objects and statement objects.
(SQLITEP, SQLITE, CHECK_SQLITE, XSQLITE): New macros for accessing
the objects.
* src/pdumper.c (dump_vectorlike): Update hash.
(dump_vectorlike): Don't dump it.
* src/print.c (print_vectorlike): Add a printer for the sqlite
object.
* src/sqlite.c: New file.
* test/src/sqlite-tests.el: Add tests.
Diffstat (limited to 'doc')
-rw-r--r-- | doc/lispref/elisp.texi | 1 | ||||
-rw-r--r-- | doc/lispref/text.texi | 146 |
2 files changed, 147 insertions, 0 deletions
diff --git a/doc/lispref/elisp.texi b/doc/lispref/elisp.texi index 4f47a1d1bbd..b773ba8fb9e 100644 --- a/doc/lispref/elisp.texi +++ b/doc/lispref/elisp.texi @@ -1224,6 +1224,7 @@ Text * Base 64:: Conversion to or from base 64 encoding. * Checksum/Hash:: Computing cryptographic hashes. * GnuTLS Cryptography:: Cryptographic algorithms imported from GnuTLS. +* Database:: Interacting with an SQL database. * Parsing HTML/XML:: Parsing HTML and XML. * Atomic Changes:: Installing several buffer changes atomically. * Change Hooks:: Supplying functions to be run when text is changed. diff --git a/doc/lispref/text.texi b/doc/lispref/text.texi index 03adb541f9b..e964d7b53c8 100644 --- a/doc/lispref/text.texi +++ b/doc/lispref/text.texi @@ -60,6 +60,7 @@ the character after point. * Base 64:: Conversion to or from base 64 encoding. * Checksum/Hash:: Computing cryptographic hashes. * GnuTLS Cryptography:: Cryptographic algorithms imported from GnuTLS. +* Database:: Interacting with an SQL database. * Parsing HTML/XML:: Parsing HTML and XML. * Parsing JSON:: Parsing and generating JSON values. * JSONRPC:: JSON Remote Procedure Call protocol @@ -5135,6 +5136,151 @@ On success, it returns a list of a binary string (the output) and the IV used. @end defun +@node Database +@section Database + + Emacs can be compiled with built-in SQLite support. + +@defun sqlite-available-p +The function returns non-@code{nil} if built-in SQLite support is +available in this Emacs session. +@end defun + +When SQLite support is available, the following functions can be used. + +@defun sqlite-open &optional file +This function opens @var{file} as a database file. If it doesn't +exist, a new database will be created and stored there. If this +argument is missing or @code{nil}, a new in-memory database is created +instead. + +The return value is a @dfn{database object} that can be used as the +argument to most of the subsequent functions in this section of the +manual. +@end defun + +@defun sqlitep +The database object returned by the @code{sqlite-open} function +satisfies this predicate. +@end defun + +@defun sqlite-close db +Close the database @var{db}. It's usually not necessary to call this +function explicitly---the database will automatically be closed if +Emacs shuts down or the database object is garbage collected. +@end defun + +@defun sqlite-execute db statement &optional values +Execute the @acronym{SQL} @var{statement}. For instance: + +@lisp +(sqlite-execute db "insert into foo values ('bar', 2)") +@end lisp + +If the optional @var{values} parameter is present, it should be either +a list or a vector of values to bind while executing the statement. +For instance: + +@lisp +(sqlite-execute db "insert into foo values (?, ?)" '("bar" 2)) +@end lisp + +This has exactly the same effect as the first form, but is more +efficient and safer (because it doesn't involve any string parsing or +interpolation). + +The number of affected rows is returned. For instance, an +@samp{insert} statement will return @samp{1}, but an @samp{update} +statement may return zero or a higher number. +@end defun + +@defun sqlite-select db query &optional values result-type +Select some data from @var{db} and return them. For instance: + +@lisp +(sqlite-select db "select * from foo where key = 2") + @result{} (("bar" 2)) +@end lisp + +As with the @code{sqlite-execute} command, you can pass in a list or a +vector of values that will be bound before executing the select: + +@lisp +(sqlite-select db "select * from foo where key = ?" [2]) + @result{} (("bar" 2)) +@end lisp + +This is usually more efficient and safer than the first method. + +This function, by default, returns a list of matching rows, where each +row is a list of column values. If @var{return-type} is @code{full}, +the names of the columns (as a list of strings) will be returned as +the first element in the return value. + +If @var{return-type} is @code{set}, this function will return a +@dfn{statement object} instead. This object can be interrogated by +the @code{sqlite-next}, @code{sqlite-columns} and @code{sqlite-more-p} +functions. If the result set is small, it's often more convenient to +just return the data directly, but if the result set is large (or if +you won't be using all the data from the set), using the @code{set} +method will allocate a lot less data, and therefore be more efficient. +@end defun + +@defun sqlite-next statement +This function returns the next row in the result set returned by +@code{sqlite-select}. + +@lisp +(sqlite-next stmt) + @result{} ("bar" 2) +@end lisp +@end defun + +@defun sqlite-columns statement +This function returns the column names of the result set returned by +@code{sqlite-select}. + +@lisp +(sqlite-columns stmt) + @result{} ("name" "issue") +@end lisp +@end defun + +@defun sqlite-more-p statement +This predicate says whether there is more data to be fetched in the +result set returned by @code{sqlite-select}. +@end defun + +@defun sqlite-finalize statement +If @var{statement} is not going to be used any more, calling this +function will free the resources bound by @var{statement}. This is +usually not necessary---when the statement object is +garbage-collected, this will happen automatically. +@end defun + +@defun sqlite-transaction db +Start a transaction in @var{db}. When in a transaction, other readers +of the database won't access the results until the transaction has +been committed. +@end defun + +@defun sqlite-commit db +End a transaction and write the data out to file. +@end defun + +@defun sqlite-rollback db +End a transaction and discard any changes that have been made. +@end defun + +@defmac with-sqlite-transaction db &body body +Like @code{progn}, but executes @var{body} with a transaction held, +and do a commit at the end. +@end defmac + +@defun sqlite-load-extension db module +Load an extension into @var{db}. Extensions are usually @file{.so} files. +@end defun + @node Parsing HTML/XML @section Parsing HTML and XML @cindex parsing html |