Hi Adam,

thanks for the "patch" hint ;-)

I changed the dbport as optional argument and added the dbpassword option
as well.

Jakob

2016-09-14 7:04 GMT+02:00 Adam Porter <a...@alphapapa.net>:

> Jakob Lombacher <ja...@lombacher.net> writes:
>
> > -(defun org-babel-sql-dbstring-postgresql (host user database)
> > +(defun org-babel-sql-dbstring-postgresql (host port user database)
>
> Hi Jakob,
>
> Two suggestions:
>
> 1.  Generally people put something like "[PATCH]" in the subject so that
> the maintainers will know it contains a patch.  :)
>
> 2.  I'd suggest putting the new `port` argument at the end of the
> argument list, after an `&optional`.  Even though it makes more sense to
> put it after the host, putting it at the end and making it optional
> means that people won't have to change existing code that calls this
> function.
>
> Thanks for submitting the patch.
>
>
>
From e92e5982c3a8db125e161d676835b47ed3806071 Mon Sep 17 00:00:00 2001
From: Jakob Lombacher <ja...@lombacher.net>
Date: Fri, 16 Sep 2016 09:12:56 +0200
Subject: [PATCH] add dbport and dbpassword options to psql

---
 lisp/ob-sql.el | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/lisp/ob-sql.el b/lisp/ob-sql.el
index 7801c5f..ed7feb8 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 user database &optional port)
   "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))))))
 
@@ -167,11 +168,12 @@ 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 \
+				  "%spsql --set=\"ON_ERROR_STOP=1\" %s -A -P \
 footer=off -F \"\t\"  %s -f %s -o %s %s"
+				  (if dbpassword (format "PGPASSWORD=%s " dbpassword) "")
 				  (if colnames-p "" "-t")
 				  (org-babel-sql-dbstring-postgresql
-				   dbhost dbuser database)
+				   dbhost dbuser database dbport)
 				  (org-babel-process-file-name in-file)
 				  (org-babel-process-file-name out-file)
 				  (or cmdline "")))
-- 
2.8.1

Reply via email to