emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[O] sqlite3 in org-babel


From: Daniel Clemente
Subject: [O] sqlite3 in org-babel
Date: Sat, 11 Feb 2012 00:18:30 +0100
User-agent: Wanderlust/2.15.9 (Almost Unreal) SEMI/1.14.6 (Maruoka) FLIM/1.14.9 (Gojō) APEL/10.8 Emacs/24.0.93 (i686-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO)

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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]