all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [PATCH] add port switch for postgresql support in ob-sql.el
@ 2016-05-19 23:37 Justin Kirby
  2016-05-22 21:47 ` Nicolas Goaziou
  0 siblings, 1 reply; 2+ messages in thread
From: Justin Kirby @ 2016-05-19 23:37 UTC (permalink / raw)
  To: emacs-org

[-- 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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] add port switch for postgresql support in ob-sql.el
  2016-05-19 23:37 [PATCH] add port switch for postgresql support in ob-sql.el Justin Kirby
@ 2016-05-22 21:47 ` Nicolas Goaziou
  0 siblings, 0 replies; 2+ messages in thread
From: Nicolas Goaziou @ 2016-05-22 21:47 UTC (permalink / raw)
  To: Justin Kirby; +Cc: emacs-org

Hello,

Justin Kirby <justinkirby@gmail.com> writes:

> I added a port switch for postgresql in ob-sql.el

Thank you for the patch. Some comments follow.

> 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?

See <http://orgmode.org/worg/dev/org-build-system.html>, in particular
BTEST_RE and BTEST_OB_LANGUAGES environment variables.

> 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

First letter should be upper case.

You also need to provide the name of the function being modified in the
commit message, e.g.

  lisp/ob-sql.el (org-babel-sql-dbstring-postgresql): Add PORT argument.
  (org-babel-execute:sql): Apply previous change.

I you haven't signed FSF papers, you also need to add TINYCHANGE at the
end of the commit message.

Could you send an updated patch ? Also, could you provide a short notice
in ORG-NEWS (located in doc/)?

Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-05-22 21:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-05-19 23:37 [PATCH] add port switch for postgresql support in ob-sql.el Justin Kirby
2016-05-22 21:47 ` Nicolas Goaziou

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.