mirror of
https://git.savannah.gnu.org/git/emacs/org-mode.git
synced 2024-11-23 07:18:53 +00:00
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.
This commit is contained in:
parent
de775a36d9
commit
553d9b5798
18
etc/ORG-NEWS
18
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
|
||||
|
||||
|
@ -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)))
|
||||
|
Loading…
Reference in New Issue
Block a user