From: Daniel Clemente <n142857@gmail.com>
To: org-mode Mailinglist <emacs-orgmode@gnu.org>
Subject: sqlite3 in org-babel
Date: Sat, 11 Feb 2012 00:18:30 +0100 [thread overview]
Message-ID: <87r4y2e0qh.wl%n142857@gmail.com> (raw)
Hi,
org-babel works well with sqlite3 if you add this (which I propose for inclusion):
-------------------------
diff --git a/lisp/ob-sql.el b/lisp/ob-sql.el
index 3f7882c..a59db7a 100644
--- a/lisp/ob-sql.el
+++ b/lisp/ob-sql.el
@@ -82,6 +82,10 @@ This function is called by `org-babel-execute-src-block'."
(org-babel-process-file-name in-file)
(org-babel-process-file-name out-file)
(or cmdline "")))
+ ('sqlite3 (format "sqlite3 %s < %s > %s"
+ (or cmdline "")
+ (org-babel-process-file-name in-file)
+ (org-babel-process-file-name out-file)))
(t (error "no support for the %s sql engine" engine)))))
(with-temp-file in-file
(insert (org-babel-expand-body:sql body params)))
-------------------------
Then you can use it in this way:
#+BEGIN_SRC sql :cmdline "-header -list ~/pruebas.sqlite3" :engine sqlite3
select * from web_categorias;
#+END_SRC
It's very useful! Org's results table is more interactive than the one you can see in sql-mode (M-x sql-sqlite).
By the way, the code in ob-sql.el attempts to remove final newlines. I use (setq require-final-newline 'ask) and I am being asked about the temporary buffer, which is wrong. So I also propose this patch:
----------------------------
diff --git a/lisp/ob-sql.el b/lisp/ob-sql.el
index 3f7882c..8df0d98 100644
--- a/lisp/ob-sql.el
+++ b/lisp/ob-sql.el
@@ -107,7 +107,8 @@ This function is called by `org-babel-execute-src-block'."
(delete-char 1)
(goto-char (point-max))
(forward-char -1))
- (write-file out-file))
+ (let ((require-final-newline nil))
+ (write-file out-file)))
(org-table-import out-file '(16))
(org-babel-reassemble-table
(mapcar (lambda (x)
----------------------------
Greetings,
Daniel
next reply other threads:[~2012-02-10 23:18 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-10 23:18 Daniel Clemente [this message]
2012-02-14 14:38 ` [babel][patch] sqlite3 in org-babel Martyn Jago
2012-02-15 15:16 ` Eric Schulte
2012-02-16 23:14 ` Daniel Clemente
2012-02-18 16:31 ` Eric Schulte
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=87r4y2e0qh.wl%n142857@gmail.com \
--to=n142857@gmail.com \
--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).