emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "Daniel M. German" <dmg@turingmachine.org>
To: emacs-orgmode@gnu.org
Subject: Add  'readonly'  option to ob-sqlite
Date: Thu, 06 Jun 2024 23:47:31 -0700	[thread overview]
Message-ID: <m2ed99dzb0.fsf@turingmachine.org> (raw)

[-- 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 .


             reply	other threads:[~2024-06-07  6:48 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-07  6:47 Daniel M. German [this message]
2024-06-07 15:04 ` Add 'readonly' option to ob-sqlite Ihor Radchenko
2024-06-23 21:07   ` dmg
2024-06-25 11:08     ` Ihor Radchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m2ed99dzb0.fsf@turingmachine.org \
    --to=dmg@turingmachine.org \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).