From mboxrd@z Thu Jan 1 00:00:00 1970 From: Justin Kirby Subject: PATCH: add dbport to ob-sql for postgres Date: Wed, 14 Sep 2016 18:18:39 -0400 Message-ID: <87mvjayvk0.fsf@openaether.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:59259) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bkIXO-0004oT-HB for emacs-orgmode@gnu.org; Wed, 14 Sep 2016 18:20:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bkIXH-0004zn-9g for emacs-orgmode@gnu.org; Wed, 14 Sep 2016 18:20:11 -0400 Received: from mail-qk0-f180.google.com ([209.85.220.180]:33411) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bkIXH-0004tF-5L for emacs-orgmode@gnu.org; Wed, 14 Sep 2016 18:20:07 -0400 Received: by mail-qk0-f180.google.com with SMTP id w204so29788883qka.0 for ; Wed, 14 Sep 2016 15:19:43 -0700 (PDT) Received: from ethiopia.gmail.com (mobile-107-107-63-150.mycingular.net. [107.107.63.150]) by smtp.gmail.com with ESMTPSA id o128sm224704qkf.17.2016.09.14.15.18.41 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Sep 2016 15:18:42 -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-orgmode@gnu.org --=-=-= Content-Type: text/plain 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 --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=pg-port.patch 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 . + +;;; 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")))) --=-=-=--