emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Justin Kirby <justinkirby@gmail.com>
To: emacs-org <emacs-orgmode@gnu.org>
Subject: [PATCH] add port switch for postgresql support in ob-sql.el
Date: Thu, 19 May 2016 19:37:18 -0400	[thread overview]
Message-ID: <878tz54o29.fsf@openaether.org> (raw)

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



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?


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-add-dbport-parameter-to-postgresql-dbstring.patch --]
[-- Type: text/x-diff, Size: 1498 bytes --]

From 4ca513afe3725fbfbefd7ad9bf54637adfd56ea2 Mon Sep 17 00:00:00 2001
From: Justin Kirby <justin@redsorbet.com>
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


             reply	other threads:[~2016-05-19 23:37 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-19 23:37 Justin Kirby [this message]
2016-05-22 21:47 ` [PATCH] add port switch for postgresql support in ob-sql.el 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=878tz54o29.fsf@openaether.org \
    --to=justinkirby@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /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).