From mboxrd@z Thu Jan 1 00:00:00 1970 From: Saulius =?utf-8?Q?Menkevi=C4=8Dius?= Subject: Re: [PATCH] lisp/ob-sql.el: add support for :dbport parameter Date: Tue, 07 Apr 2015 20:36:17 +0300 Message-ID: References: <87zj6kpilk.fsf@nicolasgoaziou.fr> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:54012) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YfXQF-00073f-Dt for emacs-orgmode@gnu.org; Tue, 07 Apr 2015 13:36:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YfXQC-0007f3-L9 for emacs-orgmode@gnu.org; Tue, 07 Apr 2015 13:36:23 -0400 Received: from mail-wg0-x22a.google.com ([2a00:1450:400c:c00::22a]:34446) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YfXQC-0007em-Ac for emacs-orgmode@gnu.org; Tue, 07 Apr 2015 13:36:20 -0400 Received: by wgbdm7 with SMTP id dm7so63760715wgb.1 for ; Tue, 07 Apr 2015 10:36:19 -0700 (PDT) In-reply-to: <87zj6kpilk.fsf@nicolasgoaziou.fr> 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-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Nicolas Goaziou Cc: emacs-orgmode@gnu.org, Saulius =?utf-8?Q?Menkevi=C4=8Dius?= --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Nicolas Goaziou writes: > Hello, > > Saulius Menkevičius writes: > >> 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. > > Thank you. > >> This is my first patch, below the 15 line threshold. >> >> From ca3f85877bdf406deefaf66cbac3483a7e41f134 Mon Sep 17 00:00:00 2001 >> From: =?UTF-8?q?Saulius=20Menkevi=C4=8Dius?= >> 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. > > You need to also specify what functions are modified, e.g., > > * lisp/ob-sql.el (org-babel-sql-dbstring-mysql): Change signature. Done. > >> +(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))) > > Isn't PORT a string already? Apparently it is not a string. I don't know the internal machinery for #+header parameters in org-mode/babel, but apparently number-to-string is required, otherwise I get the "progn: Wrong type argument: sequencep, 33060" error. Where 33060 is my port number from the :dbport param. > >> (dbhost (cdr (assoc :dbhost params))) >> + (dbport (cdr (assoc :dbport params))) > > Nitpick: `assoc' -> `assq' Ok. I did not know much of elisp to decide on which one to. This was copy-paste code from previous line, sorry. Updated patch is attached to this mail. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-ob-sql-Add-possibility-to-set-dbport.patch Content-Description: Patch for lips/ob-sql.el to support database port number >From e6d7585c4eaba775a370d40135ae8725c04751c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Saulius=20Menkevi=C4=8Dius?= Date: Mon, 6 Apr 2015 23:13:06 +0300 Subject: [PATCH] ob-sql: Add possibility to set dbport * lisp/ob-sql.el (org-babel-sql-dbstring-mysql): Change type signature to accept server port number too. (org-babel-execute:sql) Will now recognize the dbport parameter. Passed to org-babel-sql-dbstring-mysql only for now. 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..110a34d 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 (assq :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 --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit -- Saulius Menkevičius (saulius.menkevicius@gmail.com) --=-=-=--