emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "Steven Rémot" <steven.remot@gmail.com>
To: "Thomas S. Dye" <tsd@tsdye.com>
Cc: 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 13:55:44 +0200	[thread overview]
Message-ID: <541D6B40.7030501@gmail.com> (raw)
In-Reply-To: <m21tspd6hn.fsf@tsdye.com>

[-- Attachment #1: Type: text/plain, Size: 820 bytes --]

Hello,

Thomas S. Dye writes :
> If you'd like to contribute other patches, then you'll want to sign 
> the FSF papers following the instructions here: 
> http://orgmode.org/worg/org-contribute.html#sec-2 This process will 
> probably take some weeks to complete. 
I completed the copyright assignment procedure, so I come back to 
propose my changes.

To avoid you browsing your mails to find the first message, I summarize 
again the changes in this mail, and attach the patch to it.

This patch adds support for :dbhost, :dbuser and :database parameters 
for SQL code blocks that uses postgresql engine. This allows to abstract 
postgresql login details instead of sending parameters in a 
psql-specific format using :cmdline argument.

I am still at your service for any comment on the code.

Regards,
Steven Rémot

[-- Attachment #2: 0001-ob-sql.el-Enhance-postgresql-support.patch --]
[-- Type: text/x-patch, Size: 2070 bytes --]

From 6ad99759a16c8b6f9decfb8ea90c84e7a1c18fdc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Steven=20R=C3=A9mot?= <steven.remot@gmail.com>
Date: Fri, 8 Aug 2014 21:49:44 +0200
Subject: [PATCH] ob-sql.el: Enhance postgresql support

* lisp/ob-sql.el: Add support for :dbhost, :dbuser and :database
  parameters in sql code blocks for postgresql engine.

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..9fe9da2 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 dbstring-postgresql (host user database)
+  "Make PostgreSQL command line ards for database connection.
+Pass nil to omit that arg."
+  (combine-and-quote-strings
+   (remq 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")
+				  (dbstring-postgresql dbhost dbuser database)
 				  (org-babel-process-file-name in-file)
 				  (org-babel-process-file-name out-file)
 				  (or cmdline "")))
-- 
1.9.1


  parent reply	other threads:[~2014-09-20 11:56 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 [this message]
2014-09-20 12:16         ` Nicolas Goaziou
2014-09-20 13:31           ` Steven Rémot
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

  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=541D6B40.7030501@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 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).