emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] lisp/ob-sql.el: add support for :dbport parameter
@ 2015-04-06 20:34 Saulius Menkevičius
  2015-04-07  4:49 ` Xavier Maillard
  2015-04-07  6:17 ` Nicolas Goaziou
  0 siblings, 2 replies; 6+ messages in thread
From: Saulius Menkevičius @ 2015-04-06 20:34 UTC (permalink / raw)
  To: emacs-orgmode

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


This (tiny) patch implements ability to set dbport for org-babel sql
functionality. I often use ssh port forwarding to connect to remote
mysql servers where port is mapped to non-standard one on local machine.

This is my first patch, below the 15 line threshold.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: patch to support :dbport in lisp/ob-sql.el --]
[-- Type: text/x-patch, Size: 2570 bytes --]

From ca3f85877bdf406deefaf66cbac3483a7e41f134 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Saulius=20Menkevi=C4=8Dius?= <saulius.menkevicius@gmail.com>
Date: Mon, 6 Apr 2015 23:13:06 +0300
Subject: [PATCH] ob-sql: Add possibility to set dbport

 * lisp/ob-sql.el: will now recognize dbport parameter. Currently it
   is supported for mysql engine only.

TINYCHANGE
---
 lisp/ob-sql.el | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/lisp/ob-sql.el b/lisp/ob-sql.el
index 493b3dc..2de5d6e 100644
--- a/lisp/ob-sql.el
+++ b/lisp/ob-sql.el
@@ -36,6 +36,7 @@
 ;; - engine
 ;; - cmdline
 ;; - dbhost
+;; - dbport
 ;; - dbuser
 ;; - dbpassword
 ;; - database
@@ -68,6 +69,7 @@
   '((engine	       . :any)
     (out-file	       . :any)
     (dbhost	       . :any)
+    (dbport	       . :any)
     (dbuser	       . :any)
     (dbpassword	       . :any)
     (database	       . :any))
@@ -78,11 +80,12 @@
   (org-babel-sql-expand-vars
    body (mapcar #'cdr (org-babel-get-header params :var))))
 
-(defun org-babel-sql-dbstring-mysql (host user password database)
+(defun org-babel-sql-dbstring-mysql (host port user password database)
   "Make MySQL cmd 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     (concat "-P" (number-to-string port)))
 	       (when user     (concat "-u" user))
 	       (when password (concat "-p" password))
 	       (when database (concat "-D" database))))))
@@ -102,6 +105,7 @@ This function is called by `org-babel-execute-src-block'."
   (let* ((result-params (cdr (assoc :result-params params)))
          (cmdline (cdr (assoc :cmdline params)))
          (dbhost (cdr (assoc :dbhost params)))
+         (dbport (cdr (assoc :dbport params)))
          (dbuser (cdr (assoc :dbuser params)))
          (dbpassword (cdr (assoc :dbpassword params)))
          (database (cdr (assoc :database params)))
@@ -126,7 +130,7 @@ This function is called by `org-babel-execute-src-block'."
                                      (org-babel-process-file-name in-file)
                                      (org-babel-process-file-name out-file)))
                     ('mysql (format "mysql %s %s %s < %s > %s"
-				    (org-babel-sql-dbstring-mysql dbhost dbuser dbpassword database)
+				    (org-babel-sql-dbstring-mysql dbhost dbport dbuser dbpassword database)
 				    (if colnames-p "" "-N")
                                     (or cmdline "")
 				    (org-babel-process-file-name in-file)
-- 
2.3.3


[-- Attachment #3: Type: text/plain, Size: 58 bytes --]


-- 
Saulius Menkevičius (saulius.menkevicius@gmail.com)

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

end of thread, other threads:[~2015-04-07 20:26 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-04-06 20:34 [PATCH] lisp/ob-sql.el: add support for :dbport parameter Saulius Menkevičius
2015-04-07  4:49 ` Xavier Maillard
2015-04-07 17:12   ` Saulius Menkevičius
2015-04-07  6:17 ` Nicolas Goaziou
2015-04-07 17:36   ` Saulius Menkevičius
2015-04-07 20:27     ` 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).