Ihor Radchenko <yanta...@posteo.net> writes:

> However, I think that it will provide more freedom to users if you alter
> org-babel-default-header-args:sqlite instead of hard-coding the default.
> May you update the patch accordingly?

Please see the attached patch.

> Also, can you update the docs at
> https://orgmode.org/worg/org-contrib/babel/languages/ob-doc-sqlite.html
> ? The current docs declare :db header arg as mandatory.

Ditto, please see the second attached patch.

P.S. #1: This is my first contribution to the
WORG, and I am not sure if the patch is OK.
I do ever not plan to contribute to the WORG,
as I am not a fan of the idea and think that
all built-in backends (and more!) should be
documented in the Org manual.

P.S. #2: The Table of Contents (TOC) on the
WORG is "jumpy" on Safari.  In fact, it has
always been problematic for me, in one way or
another.  Why cannot TOC be included at the
beginning of the document, like in standard
Org exports?  Org and Emacs manuals, with no
"smart" side bars, get it right, IMO.

Rudy

>From aac17ad21bf5fe85a57efd4183b80fdc5221d3aa Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rudolf=20Adamkovi=C4=8D?= <salu...@me.com>
Date: Wed, 3 May 2023 14:59:03 +0200
Subject: [PATCH] ob-sqlite: Use a transient in-memory database by default

* etc/ORG-NEWS (New features): Add a news entry.
* lisp/ob-sqlite.el (org-babel-default-header-args:sqlite): Default
':db' to ":memory:".
* testing/lisp/test-ob-sqlite.el (ob-sqlite/in-file): Test the old behavior.
* testing/lisp/test-ob-sqlite.el (ob-sqlite/in-memory): Test the new behavior.
---
 etc/ORG-NEWS                   |  7 +++++++
 lisp/ob-sqlite.el              |  2 +-
 testing/lisp/test-ob-sqlite.el | 36 ++++++++++++++++++++++++++++++++--
 3 files changed, 42 insertions(+), 3 deletions(-)

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 4f16eda24..40a4e79bd 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -489,6 +489,13 @@ Final hooks are added to the following commands:
 
 The prefix arguments are passed to ~org-insert-todo-heading~.
 
+*** Make ~ob-sqlite~ use in-database by default
+
+SQLite source blocks with no ~:db~ argument now execute against a
+transient in-memory database by default.  This makes Org match the
+default behavior of the ~sqlite3~ shell and makes SQLite blocks more
+practical out of the box.
+
 *** Add support for ~logind~ idle time in ~org-user-idle-seconds~
 
 When Emacs is built with =dbus= support and
diff --git a/lisp/ob-sqlite.el b/lisp/ob-sqlite.el
index 526b73ebd..75ef50913 100644
--- a/lisp/ob-sqlite.el
+++ b/lisp/ob-sqlite.el
@@ -39,7 +39,7 @@
 (declare-function orgtbl-to-csv "org-table" (table params))
 (declare-function org-table-to-lisp "org-table" (&optional txt))
 
-(defvar org-babel-default-header-args:sqlite '())
+(defvar org-babel-default-header-args:sqlite '((:db . ":memory:")))
 
 (defvar org-babel-header-args:sqlite
   '((db        . :any)
diff --git a/testing/lisp/test-ob-sqlite.el b/testing/lisp/test-ob-sqlite.el
index 72d75c9b7..621a11b0b 100644
--- a/testing/lisp/test-ob-sqlite.el
+++ b/testing/lisp/test-ob-sqlite.el
@@ -39,8 +39,40 @@
   .import $tb TestTable
   select * from TestTable;
 #+end_src"
-	    (org-babel-next-src-block)
-	    (org-babel-execute-src-block)))))
+	   (org-babel-next-src-block)
+	   (org-babel-execute-src-block)))))
+
+(ert-deftest ob-sqlite/in-memory ()
+  "Test in-memory temporariness."
+  (should
+   (equal 0
+          (progn
+            (org-test-with-temp-text
+	     "#+BEGIN_SRC sqlite
+PRAGMA user_version = 1;
+#+END_SRC"
+	     (org-babel-execute-src-block))
+            (org-test-with-temp-text
+	     "#+BEGIN_SRC sqlite
+PRAGMA user_version;
+#+END_SRC"
+	     (org-babel-execute-src-block))))))
+
+(ert-deftest ob-sqlite/in-file ()
+  "Test in-file permanency."
+  (should
+   (equal 1
+          (let ((file (org-babel-temp-file "test" ".sqlite")))
+            (org-test-with-temp-text
+	     (format "#+BEGIN_SRC sqlite :db %s
+PRAGMA user_version = 1;
+#+END_SRC" file)
+	     (org-babel-execute-src-block))
+            (org-test-with-temp-text
+	     (format "#+BEGIN_SRC sqlite :db %s
+PRAGMA user_version;
+#+END_SRC" file)
+	     (org-babel-execute-src-block))))))
 
 (provide 'test-ob-sqlite)
 ;;; test-ob-sqlite.el ends here
-- 
2.37.1 (Apple Git-137.1)

>From 2d756f51299131727a978da3bbdfbaaa3c67d36d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rudolf=20Adamkovi=C4=8D?= <salu...@me.com>
Date: Sat, 5 Aug 2023 00:36:07 +0200
Subject: [PATCH] Document the new default value of the Babel/SQLite ':db'
 argument

---
 org-contrib/babel/languages/ob-doc-sqlite.org | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/org-contrib/babel/languages/ob-doc-sqlite.org b/org-contrib/babel/languages/ob-doc-sqlite.org
index d7febb0c..981eca34 100644
--- a/org-contrib/babel/languages/ob-doc-sqlite.org
+++ b/org-contrib/babel/languages/ob-doc-sqlite.org
@@ -91,7 +91,8 @@ There are no language-specific default header arguments for SQLite.
 There are 11 SQLite-specific header arguments.
 
  - db :: a string with the name of the file that holds the SQLite
-         database. Babel requires this header argument. 
+   database. Defaults to =":memory:"=, a special "file name" that
+   makes SQLite use a temporary in-memory database.
  - header :: if present, turn on headers in the output format. Headers
              are also output with the header argument =:colnames yes=.
  - echo :: if present, set the SQLite dot command =.echo= to =ON=.
-- 
2.37.1 (Apple Git-137.1)

-- 
"We shall not cease from exploration
 And the end of all our exploring
 Will be to arrive where we started
 And know the place for the first time"
--- T. S. Eliot, Little Gidding, Four Quarters, 1943

Rudolf Adamkovič <salu...@me.com> [he/him]
Studenohorská 25
84103 Bratislava
Slovakia

Reply via email to