From: "Steven Rémot" <steven.remot@gmail.com>
To: "Thomas S. Dye" <tsd@tsdye.com>, emacs-orgmode@gnu.org
Subject: Re: [PATCH] Add support for :dbhost, :dbuser and :database parameters for poastgresql in ob-sql.el
Date: Sat, 20 Sep 2014 15:31:08 +0200 [thread overview]
Message-ID: <541D819C.2030107@gmail.com> (raw)
In-Reply-To: <8761gia3mf.fsf@nicolasgoaziou.fr>
[-- Attachment #1: Type: text/plain, Size: 659 bytes --]
Thank you for your comments. I attached the fixed patch below.
On 09/20/2014 14:16, Nicolas Goaziou wrote:
> This is not related to your patch, but while you're at it, use `delq'
> instead of `remq' (nitpick) and `dbstring-postgresql' needs to be
> renamed `org-babel-sql-dbstring-postgresql' or some such.
I used mysql parameters handling code as a template for writing my
patch, so it suffered from the same problems. I added a second patch
that renames `dbstring-mysql' to `org-babel-sql-dbstring-mysql' and that
uses `delq' instead of `remq' in its implementation. I did some basic
tests to ensure I didn't break anything.
Regards,
Steven Rémot
[-- Attachment #2: 0001-ob-sql.el-Enhance-postgresql-support.patch --]
[-- Type: text/x-patch, Size: 2095 bytes --]
From b4584bddcc66046836c4029ab992bd8b8ed347ce Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Steven=20R=C3=A9mot?= <steven.remot@gmail.com>
Date: Sat, 20 Sep 2014 15:02:36 +0200
Subject: [PATCH 1/2] ob-sql.el: Enhance postgresql support
* lisp/ob-sql.el (org-babel-sql-dbstring-postgresql): New function
(org-babel-execute:sql): Use new function.
Before this patch, it was necessary to use :cmdline parameter to
specify host, user and database different the the default ones. Now,
this can be done using parameters that are independents of the engine
used.
This is not trivial (and not recommended) to pass password as a
command line argument to psql, so :dbpassword is not supported.
---
lisp/ob-sql.el | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/lisp/ob-sql.el b/lisp/ob-sql.el
index 7b85df8..292d5dd 100644
--- a/lisp/ob-sql.el
+++ b/lisp/ob-sql.el
@@ -87,6 +87,15 @@
(when password (concat "-p" password))
(when database (concat "-D" database))))))
+(defun org-babel-sql-dbstring-postgresql (host user database)
+ "Make PostgreSQL command line args for database connection.
+Pass nil to omit that arg."
+ (combine-and-quote-strings
+ (delq nil
+ (list (when host (concat "-h" host))
+ (when user (concat "-U" user))
+ (when database (concat "-d" database))))))
+
(defun org-babel-execute:sql (body params)
"Execute a block of Sql code with Babel.
This function is called by `org-babel-execute-src-block'."
@@ -123,8 +132,9 @@ This function is called by `org-babel-execute-src-block'."
(org-babel-process-file-name in-file)
(org-babel-process-file-name out-file)))
('postgresql (format
- "psql --set=\"ON_ERROR_STOP=1\" %s -A -P footer=off -F \"\t\" -f %s -o %s %s"
+ "psql --set=\"ON_ERROR_STOP=1\" %s -A -P footer=off -F \"\t\" %s -f %s -o %s %s"
(if colnames-p "" "-t")
+ (org-babel-sql-dbstring-postgresql dbhost dbuser database)
(org-babel-process-file-name in-file)
(org-babel-process-file-name out-file)
(or cmdline "")))
--
1.9.1
[-- Attachment #3: 0002-ob-sql.el-Clean-mysql-parameters-generation.patch --]
[-- Type: text/x-patch, Size: 1902 bytes --]
From 4cd3b02de74c74980ca0b99f7faa228f96792a47 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Steven=20R=C3=A9mot?= <steven.remot@gmail.com>
Date: Sat, 20 Sep 2014 15:09:29 +0200
Subject: [PATCH 2/2] ob-sql.el: Clean mysql parameters generation
* lisp/ob-sql.el (dbstring-mysql): Rename function and tweak a bit its
implementation
(org-babel-execute:sql): Use new function name
Prefix `dbstring-mysql' function with the namespace "org-babel-sql" to
avoid name collisions.
Also replace the call to `remq' by `delq' because it is a bit more
efficient, and also to be consistent with
`org-babel-sql-dbstring-postgresql'.
---
lisp/ob-sql.el | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/lisp/ob-sql.el b/lisp/ob-sql.el
index 292d5dd..493b3dc 100644
--- a/lisp/ob-sql.el
+++ b/lisp/ob-sql.el
@@ -78,10 +78,10 @@
(org-babel-sql-expand-vars
body (mapcar #'cdr (org-babel-get-header params :var))))
-(defun dbstring-mysql (host user password database)
+(defun org-babel-sql-dbstring-mysql (host user password database)
"Make MySQL cmd line args for database connection. Pass nil to omit that arg."
(combine-and-quote-strings
- (remq nil
+ (delq nil
(list (when host (concat "-h" host))
(when user (concat "-u" user))
(when password (concat "-p" password))
@@ -126,7 +126,7 @@ This function is called by `org-babel-execute-src-block'."
(org-babel-process-file-name in-file)
(org-babel-process-file-name out-file)))
('mysql (format "mysql %s %s %s < %s > %s"
- (dbstring-mysql dbhost dbuser dbpassword database)
+ (org-babel-sql-dbstring-mysql dbhost dbuser dbpassword database)
(if colnames-p "" "-N")
(or cmdline "")
(org-babel-process-file-name in-file)
--
1.9.1
next prev parent reply other threads:[~2014-09-20 13:31 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-08 20:11 [PATCH] Add support for :dbhost, :dbuser and :database parameters for poastgresql in ob-sql.el Steven Rémot
2014-08-09 0:38 ` Thomas S. Dye
2014-08-09 10:04 ` Steven Rémot
2014-08-09 15:31 ` Thomas S. Dye
2014-08-09 16:02 ` Steven Rémot
2014-09-20 11:55 ` Steven Rémot
2014-09-20 12:16 ` Nicolas Goaziou
2014-09-20 13:31 ` Steven Rémot [this message]
2014-09-20 21:09 ` Nicolas Goaziou
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=541D819C.2030107@gmail.com \
--to=steven.remot@gmail.com \
--cc=emacs-orgmode@gnu.org \
--cc=tsd@tsdye.com \
/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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.