emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* sqlite3 in org-babel
@ 2012-02-10 23:18 Daniel Clemente
  2012-02-14 14:38 ` [babel][patch] " Martyn Jago
  2012-02-15 15:16 ` Eric Schulte
  0 siblings, 2 replies; 5+ messages in thread
From: Daniel Clemente @ 2012-02-10 23:18 UTC (permalink / raw)
  To: org-mode Mailinglist


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

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [babel][patch] sqlite3 in org-babel
  2012-02-10 23:18 sqlite3 in org-babel Daniel Clemente
@ 2012-02-14 14:38 ` Martyn Jago
  2012-02-15 15:16 ` Eric Schulte
  1 sibling, 0 replies; 5+ messages in thread
From: Martyn Jago @ 2012-02-14 14:38 UTC (permalink / raw)
  To: emacs-orgmode

Added [babe][patch] to title to avoid patch being overlooked.

Best, Martyn

Daniel Clemente <n142857@gmail.com> writes:

> 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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: sqlite3 in org-babel
  2012-02-10 23:18 sqlite3 in org-babel Daniel Clemente
  2012-02-14 14:38 ` [babel][patch] " Martyn Jago
@ 2012-02-15 15:16 ` Eric Schulte
  2012-02-16 23:14   ` Daniel Clemente
  1 sibling, 1 reply; 5+ messages in thread
From: Eric Schulte @ 2012-02-15 15:16 UTC (permalink / raw)
  To: Daniel Clemente; +Cc: org-mode Mailinglist

Hi Daniel,

Have you tried using a sqlite code block?  See ob-sqlite.el

Best,

Daniel Clemente <n142857@gmail.com> writes:

> 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
>

-- 
Eric Schulte
http://cs.unm.edu/~eschulte/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: sqlite3 in org-babel
  2012-02-15 15:16 ` Eric Schulte
@ 2012-02-16 23:14   ` Daniel Clemente
  2012-02-18 16:31     ` Eric Schulte
  0 siblings, 1 reply; 5+ messages in thread
From: Daniel Clemente @ 2012-02-16 23:14 UTC (permalink / raw)
  To: Eric Schulte; +Cc: org-mode Mailinglist


> Have you tried using a sqlite code block?  See ob-sqlite.el

  I didn't notice there were both ob-sql and ob-sqlite. It would be useful to mention sqlite inside ob-sql.
  Perhaps they should be united?


  I still prefer ob-sql for sqlite because it lets me pass the parameter ":init /dev/null". That makes it NOT load my ~/.sqliterc (where I have a very verbose ".tables"). ob-sqlite does not have ":init" and therefore always stuffs that output into the results.



> 
> Daniel Clemente <n142857@gmail.com> writes:
> 
> > Hi,
> >    org-babel works well with sqlite3 if you add this (which I propose for inclusion):
> >

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: sqlite3 in org-babel
  2012-02-16 23:14   ` Daniel Clemente
@ 2012-02-18 16:31     ` Eric Schulte
  0 siblings, 0 replies; 5+ messages in thread
From: Eric Schulte @ 2012-02-18 16:31 UTC (permalink / raw)
  To: Daniel Clemente; +Cc: org-mode Mailinglist

Daniel Clemente <n142857@gmail.com> writes:

>> Have you tried using a sqlite code block?  See ob-sqlite.el
>
>   I didn't notice there were both ob-sql and ob-sqlite. It would be
>   useful to mention sqlite inside ob-sql.

Done.

>   
>   Perhaps they should be united?
>

I believe there were reasons for keeping them separate.  I'd rather not
combine them without a full overview of both code files.

>
>
>   I still prefer ob-sql for sqlite because it lets me pass the
> parameter ":init /dev/null". That makes it NOT load my ~/.sqliterc
> (where I have a very verbose ".tables"). ob-sqlite does not have
> ":init" and therefore always stuffs that output into the results.
>

From looking at the man page of sqlite, it seems you can do the same
with ob-sqlite.  Simply pass "--init /dev/null" to the sqlite command.
This could be done e.g. with something like

  (org-babel-sqlite3-command "sqlite3 --init /dev/null")

Best,

>
>
>
>> 
>> Daniel Clemente <n142857@gmail.com> writes:
>> 
>> > Hi,
>> >    org-babel works well with sqlite3 if you add this (which I propose for inclusion):
>> >
>

-- 
Eric Schulte
http://cs.unm.edu/~eschulte/

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2012-02-18 16:31 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-02-10 23:18 sqlite3 in org-babel Daniel Clemente
2012-02-14 14:38 ` [babel][patch] " Martyn Jago
2012-02-15 15:16 ` Eric Schulte
2012-02-16 23:14   ` Daniel Clemente
2012-02-18 16:31     ` Eric Schulte

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).