all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#70145: [PATCH] Add sqlite-execute-batch command
@ 2024-04-02 15:03 Javier Olaechea
  2024-04-02 16:21 ` Eli Zaretskii
  0 siblings, 1 reply; 12+ messages in thread
From: Javier Olaechea @ 2024-04-02 15:03 UTC (permalink / raw)
  To: 70145


[-- Attachment #1.1: Type: text/plain, Size: 1034 bytes --]

Hi, while writing tests for an Emacs package I found myself needing to
execute multiple statements against an in-memory database, to initialize
the schema. Currently there is no easy way to do so as sqlite-execute
only executes the first command and ignores the rest. The reason most
likely being that accepting arguments for multiple statements and
properly preparing would be a tricky task. So instead I'm adding the
functionality as a new function that takes no arguments.


In GNU Emacs 29.1 (build 1, x86_64-pc-linux-gnu, X toolkit, cairo
version 1.18.0, Xaw3d scroll bars)
Windowing system distributor 'The X.Org Foundation', version 11.0.12013000
System Description: Ubuntu 20.04.6 LTS

Configured using:
 'configure
 --prefix=/nix/store/0g4xxdsn4xp9qhgc4cylbksqpwsn51vc-emacs-29.1
 --disable-build-details --with-modules --with-x-toolkit=lucid
 --with-xft --with-cairo --with-native-compilation --with-tree-sitter
 --with-xinput2'

-- 
"I object to doing things that computers can do." — Olin Shivers

[-- Attachment #1.2: Type: text/html, Size: 1268 bytes --]

[-- Attachment #2: 0001-Add-sqlite-execute-batch-command.patch --]
[-- Type: text/x-patch, Size: 2202 bytes --]

From 454b23cb31332fbd5b5d2c5117394c578581b72b Mon Sep 17 00:00:00 2001
From: Javier Olaechea <pirata@gmail.com>
Date: Sun, 31 Mar 2024 23:07:10 -0500
Subject: [PATCH] Add sqlite-execute-batch command

This command is similar to sqlite-execute except that it executes
multiple statements in exchange for not accepting any arguments.

* doc/lispref/text.texi (Database): Document it.
* src/sqlite.c (Fsqlite_execute_batch): Add sqlite_execute_batch
command. It is similar to sqlite-execute but it executes all the
statements in the query. Unlike sqlite-execute the command doesn't take
any arguments to pass down to the statements.
---
 doc/lispref/text.texi |  6 ++++++
 src/sqlite.c          | 10 ++++++++++
 2 files changed, 16 insertions(+)

diff --git a/doc/lispref/text.texi b/doc/lispref/text.texi
index 90e2c6ce882..cad6df52e55 100644
--- a/doc/lispref/text.texi
+++ b/doc/lispref/text.texi
@@ -5404,6 +5404,12 @@ Database
 
 @end defun
 
+@defun sqlite-execute-batch db statements
+Execute the @acronym{SQL} @var{statements}. This might be useful when we
+want to execute multiple @acronym{DDL} statements.
+
+@end defun
+
 @defun sqlite-select db query &optional values return-type
 Select some data from @var{db} and return them.  For instance:
 
diff --git a/src/sqlite.c b/src/sqlite.c
index 261080da673..043801459d2 100644
--- a/src/sqlite.c
+++ b/src/sqlite.c
@@ -646,6 +646,15 @@ sqlite_exec (sqlite3 *sdb, const char *query)
   return Qt;
 }
 
+DEFUN ("sqlite-execute-batch", Fsqlite_execute_batch, Ssqlite_execute_batch, 2, 2, 0,
+       doc: /* Execute multiple SQL statements.  */)
+  (Lisp_Object db, Lisp_Object query)
+{
+  check_sqlite (db, false);
+  CHECK_STRING (query);
+  return sqlite_exec (XSQLITE (db)->db, SSDATA (query));
+}
+
 DEFUN ("sqlite-transaction", Fsqlite_transaction, Ssqlite_transaction, 1, 1, 0,
        doc: /* Start a transaction in DB.  */)
   (Lisp_Object db)
@@ -866,6 +875,7 @@ syms_of_sqlite (void)
   defsubr (&Ssqlite_close);
   defsubr (&Ssqlite_execute);
   defsubr (&Ssqlite_select);
+  defsubr (&Ssqlite_execute_batch);
   defsubr (&Ssqlite_transaction);
   defsubr (&Ssqlite_commit);
   defsubr (&Ssqlite_rollback);
-- 
2.29.2.154.g7f7ebe054a


^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2024-06-06 10:08 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-02 15:03 bug#70145: [PATCH] Add sqlite-execute-batch command Javier Olaechea
2024-04-02 16:21 ` Eli Zaretskii
2024-04-02 18:52   ` Javier Olaechea
2024-04-02 18:56     ` Eli Zaretskii
2024-04-02 19:10       ` Javier Olaechea
2024-04-03  1:56         ` J.P.
2024-04-03  2:42           ` Javier Olaechea
2024-04-13  8:03             ` Eli Zaretskii
2024-04-14  3:32               ` Javier Olaechea
2024-04-14  5:52                 ` Eli Zaretskii
2024-06-06  8:00                 ` Javier Olaechea
2024-06-06 10:08                 ` Eli Zaretskii

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.