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-execute:sqlite): Default ':db' to ":memory:" instead of throwing an error. * 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.
This commit is contained in:
parent
2f79c63c2c
commit
68aa438857
|
@ -492,6 +492,14 @@ Final hooks are added to the following commands:
|
||||||
|
|
||||||
The prefix arguments are passed to ~org-insert-todo-heading~.
|
The prefix arguments are passed to ~org-insert-todo-heading~.
|
||||||
|
|
||||||
|
*** Make ~ob-sqlite~ use in-memory databases by default
|
||||||
|
|
||||||
|
~sqlite~ source blocks with no ~:db~ header argument now make SQLite
|
||||||
|
use a temporary in-memory database instead of throwing an error,
|
||||||
|
matching the behavior of the official ~sqlite3~ shell. As a result,
|
||||||
|
~sqlite~ source blocks are now usable out of the box, that is with no
|
||||||
|
header arguments.
|
||||||
|
|
||||||
*** Add support for ~logind~ idle time in ~org-user-idle-seconds~
|
*** Add support for ~logind~ idle time in ~org-user-idle-seconds~
|
||||||
|
|
||||||
When Emacs is built with =dbus= support and
|
When Emacs is built with =dbus= support and
|
||||||
|
|
|
@ -74,7 +74,6 @@ This function is called by `org-babel-execute-src-block'."
|
||||||
(lambda (arg) (car (assq arg params)))
|
(lambda (arg) (car (assq arg params)))
|
||||||
(list :header :echo :bail :column
|
(list :header :echo :bail :column
|
||||||
:csv :html :line :list)))))
|
:csv :html :line :list)))))
|
||||||
(unless db (error "ob-sqlite: can't evaluate without a database"))
|
|
||||||
(with-temp-buffer
|
(with-temp-buffer
|
||||||
(insert
|
(insert
|
||||||
(org-babel-eval
|
(org-babel-eval
|
||||||
|
@ -97,7 +96,7 @@ This function is called by `org-babel-execute-src-block'."
|
||||||
(member :html others) separator)
|
(member :html others) separator)
|
||||||
""
|
""
|
||||||
"-csv"))
|
"-csv"))
|
||||||
(cons "db " db)))
|
(cons "db" (or db ""))))
|
||||||
;; body of the code block
|
;; body of the code block
|
||||||
(org-babel-expand-body:sqlite body params)))
|
(org-babel-expand-body:sqlite body params)))
|
||||||
(org-babel-result-cond result-params
|
(org-babel-result-cond result-params
|
||||||
|
|
|
@ -39,8 +39,40 @@
|
||||||
.import $tb TestTable
|
.import $tb TestTable
|
||||||
select * from TestTable;
|
select * from TestTable;
|
||||||
#+end_src"
|
#+end_src"
|
||||||
(org-babel-next-src-block)
|
(org-babel-next-src-block)
|
||||||
(org-babel-execute-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)
|
(provide 'test-ob-sqlite)
|
||||||
;;; test-ob-sqlite.el ends here
|
;;; test-ob-sqlite.el ends here
|
||||||
|
|
Loading…
Reference in New Issue