From mboxrd@z Thu Jan 1 00:00:00 1970 From: =?UTF-8?B?U3RldmVuIFLDqW1vdA==?= Subject: [PATCH] Add support for :dbhost, :dbuser and :database parameters for poastgresql in ob-sql.el Date: Fri, 08 Aug 2014 22:11:49 +0200 Message-ID: <53E52F05.3040106@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------090000050104060508030708" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:34280) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XFqWA-0003jD-HT for emacs-orgmode@gnu.org; Fri, 08 Aug 2014 16:12:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XFqW1-00084Z-Fh for emacs-orgmode@gnu.org; Fri, 08 Aug 2014 16:12:02 -0400 Received: from mail-wi0-x229.google.com ([2a00:1450:400c:c05::229]:44219) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XFqW1-000840-8b for emacs-orgmode@gnu.org; Fri, 08 Aug 2014 16:11:53 -0400 Received: by mail-wi0-f169.google.com with SMTP id n3so3030031wiv.0 for ; Fri, 08 Aug 2014 13:11:51 -0700 (PDT) Received: from [192.168.1.14] (APuteaux-653-1-155-168.w86-195.abo.wanadoo.fr. [86.195.110.168]) by mx.google.com with ESMTPSA id q5sm10612068wiw.5.2014.08.08.13.11.50 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 08 Aug 2014 13:11:50 -0700 (PDT) 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: emacs-orgmode@gnu.org This is a multi-part message in MIME format. --------------090000050104060508030708 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Hi, I did some changes to support :dbname, :dbhost and :database in SQL code blocks when using postgresql engine. Even if it was possible to specify this information using :cmdline parameter, I thought it was a bit cleaner to be able to provide this information in a way independent from the command line. I will gladly accept any remark / comment on this patch. Regards, Steven RĂ©mot --------------090000050104060508030708 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 --------------090000050104060508030708--