* [BUG] ob-sqlite.el, -init doesn't work with some options
@ 2010-11-09 19:22 Łukasz Stelmach
2010-11-09 20:29 ` Eric Schulte
0 siblings, 1 reply; 4+ messages in thread
From: Łukasz Stelmach @ 2010-11-09 19:22 UTC (permalink / raw)
To: emacs-orgmode
Hello.
ob-sqlite.el uses -init option to provide sqlite with a src block
content, however, this prevetns sevarl options' from taking an
effect. Particularly -header (and it's opposite), -csv and -header
Create a database, put a SELECT into a file and compare the effects of
the following commands
sqlite3 -init file.sql -header -separator ';' -csv db.sqlite
cat file.sql | sqlite3 -header -separator ';' -csv db.sqlite
A walkaround is to place desired configration commands (the onse
beginning with a dot in sqlite) in the src block, e.g:
#+BEGIN_SRC sqlite :db passwords.sqlite :results replace
.separator |
.mode csv
select * from myusers;
#+END_SRC
--
Miłego dnia,
Łukasz Stelmach
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [BUG] ob-sqlite.el, -init doesn't work with some options
2010-11-09 19:22 [BUG] ob-sqlite.el, -init doesn't work with some options Łukasz Stelmach
@ 2010-11-09 20:29 ` Eric Schulte
2010-11-10 19:45 ` Łukasz Stelmach
0 siblings, 1 reply; 4+ messages in thread
From: Eric Schulte @ 2010-11-09 20:29 UTC (permalink / raw)
To: Łukasz Stelmach; +Cc: emacs-orgmode
Hi Łukasz,
Thanks for mentioning this issue and for posting a workaround.
Would you suggest a different method of passing the body of a sqlite
code block to the sqlite command? The only other options which
immediately occurs to me would involve =cat='ing the body of the code
block through a pipe to the sqlite command (which would probably only
work on unix systems).
Thanks -- Eric
Łukasz Stelmach <lukasz.stelmach@iem.pw.edu.pl> writes:
> Hello.
>
> ob-sqlite.el uses -init option to provide sqlite with a src block
> content, however, this prevetns sevarl options' from taking an
> effect. Particularly -header (and it's opposite), -csv and -header
> Create a database, put a SELECT into a file and compare the effects of
> the following commands
>
> sqlite3 -init file.sql -header -separator ';' -csv db.sqlite
>
> cat file.sql | sqlite3 -header -separator ';' -csv db.sqlite
>
> A walkaround is to place desired configration commands (the onse
> beginning with a dot in sqlite) in the src block, e.g:
>
> #+BEGIN_SRC sqlite :db passwords.sqlite :results replace
> .separator |
> .mode csv
> select * from myusers;
> #+END_SRC
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [BUG] ob-sqlite.el, -init doesn't work with some options
2010-11-09 20:29 ` Eric Schulte
@ 2010-11-10 19:45 ` Łukasz Stelmach
2010-11-10 21:03 ` Eric Schulte
0 siblings, 1 reply; 4+ messages in thread
From: Łukasz Stelmach @ 2010-11-10 19:45 UTC (permalink / raw)
To: emacs-orgmode
"Eric Schulte" <schulte.eric@gmail.com> writes:
> Łukasz Stelmach <lukasz.stelmach@iem.pw.edu.pl> writes:
>
>> ob-sqlite.el uses -init option to provide sqlite with a src block
>> content, however, this prevetns sevarl options' from taking an
>> effect. Particularly -header (and it's opposite), -csv and -header
[...]
> Thanks for mentioning this issue and for posting a workaround.
>
> Would you suggest a different method of passing the body of a sqlite
> code block to the sqlite command? The only other options which
> immediately occurs to me would involve =cat='ing the body of the code
> block through a pipe to the sqlite command (which would probably only
> work on unix systems).
I think this is the way we are supposed to do this from sqlite's point
of view as -init is rather somthing like rc file that prepares the
envioronment for further work. As far as cat(1) is concerned, please
remember that windows is alergic and doesn't keep one, it holds =type=.
IMHO the cleanest way of pushing commands to Emacs' child's stdin is
=shell-command-on-region=, which should work on every OS Emacs works.
--
Miłego dnia,
Łukasz Stelmach
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Re: [BUG] ob-sqlite.el, -init doesn't work with some options
2010-11-10 19:45 ` Łukasz Stelmach
@ 2010-11-10 21:03 ` Eric Schulte
0 siblings, 0 replies; 4+ messages in thread
From: Eric Schulte @ 2010-11-10 21:03 UTC (permalink / raw)
To: Łukasz Stelmach; +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 329 bytes --]
Hi Łukasz,
Please try out the attached patch which pushed code block bodies to the
sqlite command using org-babel-eval (which itself uses the
shell-command-on-region command).
This patch works for me. If it works for you and solves your issue,
then I'll push it through to the Org-mode core.
Much Thanks -- Eric
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ob-sqlite-pass-the-body-to-the-sqlite-command-throug.patch --]
[-- Type: text/x-diff, Size: 1893 bytes --]
From 9adf6cd33421882f351e8ca8fa56a037b665f619 Mon Sep 17 00:00:00 2001
From: Eric Schulte <schulte.eric@gmail.com>
Date: Wed, 10 Nov 2010 14:00:53 -0700
Subject: [PATCH] ob-sqlite: pass the body to the sqlite command through a pipe
* lisp/ob-sqlite.el (ob-eval): require ob-eval for external command
execution
(org-babel-execute:sqlite): no longer uses the init option for
passing commands to sqlite
---
lisp/ob-sqlite.el | 14 ++++++--------
1 files changed, 6 insertions(+), 8 deletions(-)
diff --git a/lisp/ob-sqlite.el b/lisp/ob-sqlite.el
index c744e43..dd4ea87 100644
--- a/lisp/ob-sqlite.el
+++ b/lisp/ob-sqlite.el
@@ -28,6 +28,7 @@
;;; Code:
(require 'ob)
+(require 'ob-eval)
(require 'ob-ref)
(declare-function org-fill-template "org" (template alist))
@@ -65,15 +66,10 @@ This function is called by `org-babel-execute-src-block'."
(unless db (error "ob-sqlite: can't evaluate without a database."))
(with-temp-buffer
(insert
- (shell-command-to-string
+ (org-babel-eval
(org-fill-template
- "%cmd -init %body %header %separator %nullvalue %others %csv %db "
+ "%cmd %header %separator %nullvalue %others %csv %db "
(list
- (cons "body" ((lambda (sql-file)
- (with-temp-file sql-file
- (insert (org-babel-expand-body:sqlite body params)))
- sql-file)
- (org-babel-temp-file "sqlite-sql-")))
(cons "cmd" org-babel-sqlite3-command)
(cons "header" (if headers-p "-header" "-noheader"))
(cons "separator"
@@ -90,7 +86,9 @@ This function is called by `org-babel-execute-src-block'."
(member :html others) separator)
""
"-csv"))
- (cons "db " db)))))
+ (cons "db " db)))
+ ;; body of the code block
+ (org-babel-expand-body:sqlite body params)))
(if (or (member "scalar" result-params)
(member "html" result-params)
(member "code" result-params)
--
1.7.0.4
[-- Attachment #3: Type: text/plain, Size: 1227 bytes --]
Łukasz Stelmach <lukasz.stelmach@iem.pw.edu.pl> writes:
> "Eric Schulte" <schulte.eric@gmail.com> writes:
>
>> Łukasz Stelmach <lukasz.stelmach@iem.pw.edu.pl> writes:
>>
>>> ob-sqlite.el uses -init option to provide sqlite with a src block
>>> content, however, this prevetns sevarl options' from taking an
>>> effect. Particularly -header (and it's opposite), -csv and -header
> [...]
>> Thanks for mentioning this issue and for posting a workaround.
>>
>> Would you suggest a different method of passing the body of a sqlite
>> code block to the sqlite command? The only other options which
>> immediately occurs to me would involve =cat='ing the body of the code
>> block through a pipe to the sqlite command (which would probably only
>> work on unix systems).
>
> I think this is the way we are supposed to do this from sqlite's point
> of view as -init is rather somthing like rc file that prepares the
> envioronment for further work. As far as cat(1) is concerned, please
> remember that windows is alergic and doesn't keep one, it holds =type=.
> IMHO the cleanest way of pushing commands to Emacs' child's stdin is
> =shell-command-on-region=, which should work on every OS Emacs works.
[-- Attachment #4: Type: text/plain, Size: 201 bytes --]
_______________________________________________
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2010-11-10 21:03 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-11-09 19:22 [BUG] ob-sqlite.el, -init doesn't work with some options Łukasz Stelmach
2010-11-09 20:29 ` Eric Schulte
2010-11-10 19:45 ` Łukasz Stelmach
2010-11-10 21:03 ` 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).