From mboxrd@z Thu Jan 1 00:00:00 1970 From: =?UTF-8?B?U3RldmVuIFLDqW1vdA==?= 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 Message-ID: <541D6B40.7030501@gmail.com> References: <53E52F05.3040106@gmail.com> <53E5F215.10103@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------070806070502090009070507" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:33232) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XVJGg-00015i-BK for emacs-orgmode@gnu.org; Sat, 20 Sep 2014 07:56:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XVJGa-0002GI-Gl for emacs-orgmode@gnu.org; Sat, 20 Sep 2014 07:55:58 -0400 Received: from mail-wg0-x229.google.com ([2a00:1450:400c:c00::229]:45326) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XVJGa-0002Fu-9o for emacs-orgmode@gnu.org; Sat, 20 Sep 2014 07:55:52 -0400 Received: by mail-wg0-f41.google.com with SMTP id k14so512951wgh.24 for ; Sat, 20 Sep 2014 04:55:45 -0700 (PDT) In-Reply-To: List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: "Thomas S. Dye" Cc: emacs-orgmode@gnu.org This is a multi-part message in MIME format. --------------070806070502090009070507 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit 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 --------------070806070502090009070507 Content-Type: text/x-patch; name="0001-ob-sql.el-Enhance-postgresql-support.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0001-ob-sql.el-Enhance-postgresql-support.patch" >From 6ad99759a16c8b6f9decfb8ea90c84e7a1c18fdc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steven=20R=C3=A9mot?= 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 --------------070806070502090009070507--