From mboxrd@z Thu Jan 1 00:00:00 1970 From: Justin Kirby Subject: [PATCH] add port switch for postgresql support in ob-sql.el Date: Thu, 19 May 2016 19:37:18 -0400 Message-ID: <878tz54o29.fsf@openaether.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:55611) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b3XVP-0000uT-6e for emacs-orgmode@gnu.org; Thu, 19 May 2016 19:37:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b3XVJ-00027x-5J for emacs-orgmode@gnu.org; Thu, 19 May 2016 19:37:26 -0400 Received: from mail-ig0-x230.google.com ([2607:f8b0:4001:c05::230]:36573) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b3XVI-00027r-Vz for emacs-orgmode@gnu.org; Thu, 19 May 2016 19:37:21 -0400 Received: by mail-ig0-x230.google.com with SMTP id qe5so121998914igc.1 for ; Thu, 19 May 2016 16:37:20 -0700 (PDT) Received: from ethiopia.gmail.com (cpe-66-66-115-41.rochester.res.rr.com. [66.66.115.41]) by smtp.gmail.com with ESMTPSA id l80sm509962itl.14.2016.05.19.16.37.18 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 May 2016 16:37:18 -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" To: emacs-org --=-=-= Content-Type: text/plain I added a port switch for postgresql in ob-sql.el If you have sql loaded and do something like the follow: #+name: example #+header: :engine postgresql #+header: :dbhost localhost #+header: :dbport 6543 #+header: :dbuser orgmode #+header: :database ob-sql #+BEGIN_SRC sql select * from everything #+END_SRC Note: default port for postrgres is 5432 not 6543 You will be either presented with an error or in my case a failed password prompt since I had multiple db servers running. The problem was that org-babel-sql-dbstring-postgresql did not accept a port argument. I have attached a simple patch to fix this and have verified it works for me. I would have loved to add some tests, but I ran into some problems: 1) I could not figure out how to get just one test file to run 2) I was not able get make test to load the sql language in babel Is there a recommended/standard way to resolve these problems with tests? --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-add-dbport-parameter-to-postgresql-dbstring.patch >From 4ca513afe3725fbfbefd7ad9bf54637adfd56ea2 Mon Sep 17 00:00:00 2001 From: Justin Kirby Date: Wed, 18 May 2016 23:14:48 -0400 Subject: [PATCH] add dbport parameter to postgresql dbstring If postgesql is running on a different port or using a ssh tunnel to remote db, the ability to specify a different port is needed. --- lisp/ob-sql.el | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lisp/ob-sql.el b/lisp/ob-sql.el index 6488afe..5f96aa3 100644 --- a/lisp/ob-sql.el +++ b/lisp/ob-sql.el @@ -90,12 +90,13 @@ (when password (concat "-p" password)) (when database (concat "-D" database)))))) -(defun org-babel-sql-dbstring-postgresql (host user database) +(defun org-babel-sql-dbstring-postgresql (host port 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 port (format "-p%d" port)) (when user (concat "-U" user)) (when database (concat "-d" database)))))) @@ -145,7 +146,7 @@ This function is called by `org-babel-execute-src-block'." footer=off -F \"\t\" %s -f %s -o %s %s" (if colnames-p "" "-t") (org-babel-sql-dbstring-postgresql - dbhost dbuser database) + dbhost dbport dbuser database) (org-babel-process-file-name in-file) (org-babel-process-file-name out-file) (or cmdline ""))) -- 2.6.3 --=-=-=--