emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* PATCH: add dbport to ob-sql for postgres
@ 2016-09-14 22:18 Justin Kirby
  2016-09-15  1:26 ` Nick Dokos
  0 siblings, 1 reply; 3+ messages in thread
From: Justin Kirby @ 2016-09-14 22:18 UTC (permalink / raw)
  To: emacs-orgmode

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


In ob-sql postgres would ignore dbport header argument. Attached is a
patch that corrects this.

Let me know if there are any modifications needed.

thnx,
Justin


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: pg-port.patch --]
[-- Type: text/x-diff, Size: 2899 bytes --]

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 6e003d2..f6a83e8 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -519,6 +519,8 @@ to force opening it in either Emacs or with system application.
 Allows J source blocks be indicated by letter j.  Previously the
 indication letter was solely J.
 
+*** Add port argument to ~org-babel-sql-dbstring-postgresql~
+    Can now use dbport argument in #+header for postgresql engine in org-ob-sql
 * Version 8.3
 
 ** Incompatible changes
diff --git a/lisp/ob-sql.el b/lisp/ob-sql.el
index 7801c5f..f8824c8 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))))))
 
@@ -171,7 +172,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 "")))
diff --git a/testing/lisp/test-ob-sql.el b/testing/lisp/test-ob-sql.el
new file mode 100644
index 0000000..0a7fe7e
--- /dev/null
+++ b/testing/lisp/test-ob-sql.el
@@ -0,0 +1,26 @@
+;;; test-ob-sql.el --- tests for ob-sql.el
+
+;; This file is not part of GNU Emacs.
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+;;; Code:
+(unless (featurep 'ob-sql)
+  (signal 'missing-test-dependency "Support for SQL code blocks"))
+
+(ert-deftest test-ob-sql/postgresql-dbstring-with-port ()
+    (should (string-match "-hlocalhost -p4242 -Uorg -dbabel"
+		  (org-babel-sql-dbstring-postgresql "localhost" 4242 "org" "babel")))
+    (should (string-match "-hlocalhost -Uorg -dbabel"
+		  (org-babel-sql-dbstring-postgresql "localhost" nil "org" "babel"))))

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

end of thread, other threads:[~2016-09-15 13:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-09-14 22:18 PATCH: add dbport to ob-sql for postgres Justin Kirby
2016-09-15  1:26 ` Nick Dokos
2016-09-15 13:30   ` Nicolas Goaziou

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).