branch: externals/org
commit 553d9b5798c6f8af3c254cab25e0654e5e364b74
Author: Daniel M German <d...@turingmachine.org>
Commit: Ihor Radchenko <yanta...@posteo.net>

    ob-sqlite: Add ability to open a database in readonly mode
    
    * lisp/ob-sqlite.el (org-babel-header-args:sqlite):
    (org-babel-execute:sqlite): Add new header argument :readonly.
    * etc/ORG-NEWS (ob-sqlite: Added ability to open a database in
    readonly mode): Announce the new header argument.
---
 etc/ORG-NEWS      | 18 ++++++++++++++++++
 lisp/ob-sqlite.el | 10 +++++++---
 2 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 30a78c4ebb..7c6ac5efc8 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -76,6 +76,24 @@ bibliography format requires them to be written in 
title-case.
 
 # This also includes changes in function behavior from Elisp perspective.
 
+*** ob-sqlite: Added ability to open a database in readonly mode
+
+Added option :readonly to ob-sqlite.
+
+When :readonly=true the database is opened in readonly mode. For example:
+
+#+begin_src sqlite :db /tmp/rip.db  :readonly yes  :exports both
+create table rip(a,b);
+#+end_src
+
+This results in an error such as:
+
+#+begin_example
+Runtime error near line 2: attempt to write a readonly database (8)
+[ Babel evaluation exited with code 1 ]
+#+end_example
+
+
 ** Miscellaneous
 *** Trailing =-= is now allowed in plain links
 
diff --git a/lisp/ob-sqlite.el b/lisp/ob-sqlite.el
index 96d93b815b..eb992e156c 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-p . ((yes no))))
   "Sqlite specific header args.")
 
 (defun org-babel-expand-body:sqlite (body params)
@@ -76,7 +77,8 @@ This function is called by `org-babel-execute-src-block'."
        (db (cdr (assq :db params)))
        (separator (cdr (assq :separator params)))
        (nullvalue (cdr (assq :nullvalue params)))
-       (headers-p (equal "yes" (cdr (assq :colnames params))))
+        (headers-p (equal "yes" (cdr (assq :colnames params))))
+        (readonly-p (equal "yes" (cdr (assq :readonly params))))
        (others (delq nil (mapcar
                           (lambda (arg) (car (assq arg params)))
                           (list :header :echo :bail :column
@@ -85,7 +87,7 @@ This function is called by `org-babel-execute-src-block'."
       (insert
        (org-babel-eval
        (org-fill-template
-        "%cmd %header %separator %nullvalue %others %csv %db "
+        "%cmd %header %separator %nullvalue %others %csv %readonly %db "
         (list
          (cons "cmd" org-babel-sqlite3-command)
          (cons "header" (if headers-p "-header" "-noheader"))
@@ -103,6 +105,8 @@ This function is called by `org-babel-execute-src-block'."
                              (member :html others) separator)
                          ""
                        "-csv"))
+         (cons "readonly"
+               (if readonly-p "-readonly" ""))
           (cons "db" (or db ""))))
        ;; body of the code block
        (org-babel-expand-body:sqlite body params)))

Reply via email to