all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Add  'readonly'  option to ob-sqlite
@ 2024-06-07  6:47 Daniel M. German
  2024-06-07 15:04 ` Ihor Radchenko
  0 siblings, 1 reply; 4+ messages in thread
From: Daniel M. German @ 2024-06-07  6:47 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 600 bytes --]



hi everybody,

Sometimes I think it is useful to open a DB in readonly mode

eg. to avoid modifying by mistake

This is a patch to ob-sqlite.el to accomplish that

It adds support for opening a sqlite database in readonly only.

It does it by adding a babel parameter readonly. If present, the
database will be opened in readonly mode. Example:

#+begin_src sqlite :readonly :db /tmp/rip.db
insert into a values (1,2);
select * from a;
#+end_src

This will result in the following error:

Runtime error near line 2: attempt to write a readonly database (8)
[ Babel evaluation exited with code 1 ]


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ob-sqlite.el-add-a-new-parameter-called-readonly.patch --]
[-- Type: text/x-patch, Size: 1756 bytes --]

From 7df14e4ac2dcdc8fbdf647bff31c9e03f33bd73a Mon Sep 17 00:00:00 2001
From: Daniel M German <dmg@turingmachine.org>
Date: Thu, 6 Jun 2024 23:34:28 -0700
Subject: [PATCH] lisp/ob-sqlite.el: add a new parameter called readonly.

If present, the database is open in read-only mode.

This is implemented by passing the parameter -readonly to sqlite
---
 lisp/ob-sqlite.el | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/lisp/ob-sqlite.el b/lisp/ob-sqlite.el
index 96d93b815..b15c4f4d3 100644
--- a/lisp/ob-sqlite.el
+++ b/lisp/ob-sqlite.el
@@ -52,7 +52,8 @@
     (line      . :any)
     (list      . :any)
     (separator . :any)
-    (nullvalue . :any))
+    (nullvalue . :any)
+    (readonly  . :any))
   "Sqlite specific header args.")
 
 (defun org-babel-expand-body:sqlite (body params)
@@ -77,10 +78,10 @@ This function is called by `org-babel-execute-src-block'."
 	(separator (cdr (assq :separator params)))
 	(nullvalue (cdr (assq :nullvalue params)))
 	(headers-p (equal "yes" (cdr (assq :colnames params))))
-	(others (delq nil (mapcar
+        (others (delq nil (mapcar
 			   (lambda (arg) (car (assq arg params)))
 			   (list :header :echo :bail :column
-				 :csv :html :line :list)))))
+				 :csv :html :line :list :readonly)))))
     (with-temp-buffer
       (insert
        (org-babel-eval
@@ -88,7 +89,7 @@ This function is called by `org-babel-execute-src-block'."
 	 "%cmd %header %separator %nullvalue %others %csv %db "
 	 (list
 	  (cons "cmd" org-babel-sqlite3-command)
-	  (cons "header" (if headers-p "-header" "-noheader"))
+          (cons "header" (if headers-p "-header" "-noheader"))
 	  (cons "separator"
 		(if separator (format "-separator %s" separator) ""))
 	  (cons "nullvalue"
-- 
2.45.1


[-- Attachment #3: Type: text/plain, Size: 248 bytes --]




--
Daniel M. German                  "A machine --computer-- can only do
   Lady Lovelace ->                what we tell it to do"
http://turingmachine.org/
http://silvernegative.com/
dmg (at) uvic (dot) ca
replace (at) with @ and (dot) with .


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

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

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-07  6:47 Add 'readonly' option to ob-sqlite Daniel M. German
2024-06-07 15:04 ` Ihor Radchenko
2024-06-23 21:07   ` dmg
2024-06-25 11:08     ` Ihor Radchenko

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.