From: "Saulius Menkevičius" <saulius.menkevicius@gmail.com>
To: emacs-orgmode@gnu.org
Subject: [PATCH] lisp/ob-sql.el: add support for :dbport parameter
Date: Mon, 06 Apr 2015 23:34:50 +0300 [thread overview]
Message-ID: <m28ue5ov11.fsf@mbp.Dlink> (raw)
[-- 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)
next reply other threads:[~2015-04-06 20:34 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-06 20:34 Saulius Menkevičius [this message]
2015-04-07 4:49 ` [PATCH] lisp/ob-sql.el: add support for :dbport parameter 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m28ue5ov11.fsf@mbp.Dlink \
--to=saulius.menkevicius@gmail.com \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).