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

* Re: [PATCH] lisp/ob-sql.el: add support for :dbport parameter
  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
  1 sibling, 1 reply; 6+ messages in thread
From: Xavier Maillard @ 2015-04-07  4:49 UTC (permalink / raw)
  To: Saulius Menkevičius; +Cc: emacs-orgmode


Saulius Menkevičius <saulius.menkevicius@gmail.com> 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.
>
> This is my first patch, below the 15 line threshold.

Seems good AFAICS.

Do you often use orgmode, BABEL and sql all together ? (just curious
as I am a DBA in real life).

-- Xavier.

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

* Re: [PATCH] lisp/ob-sql.el: add support for :dbport parameter
  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  6:17 ` Nicolas Goaziou
  2015-04-07 17:36   ` Saulius Menkevičius
  1 sibling, 1 reply; 6+ messages in thread
From: Nicolas Goaziou @ 2015-04-07  6:17 UTC (permalink / raw)
  To: Saulius Menkevičius; +Cc: emacs-orgmode

Hello,

Saulius Menkevičius <saulius.menkevicius@gmail.com> 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?= <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.

You need to also specify what functions are modified, e.g.,

* lisp/ob-sql.el (org-babel-sql-dbstring-mysql): Change signature.

> +(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?

>           (dbhost (cdr (assoc :dbhost params)))
> +         (dbport (cdr (assoc :dbport params)))

Nitpick: `assoc' -> `assq'


Regards,

-- 
Nicolas Goaziou

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

* Re: [PATCH] lisp/ob-sql.el: add support for :dbport parameter
  2015-04-07  4:49 ` Xavier Maillard
@ 2015-04-07 17:12   ` Saulius Menkevičius
  0 siblings, 0 replies; 6+ messages in thread
From: Saulius Menkevičius @ 2015-04-07 17:12 UTC (permalink / raw)
  To: Xavier Maillard; +Cc: emacs-orgmode, Saulius Menkevičius


Xavier Maillard writes:

> Saulius Menkevičius <saulius.menkevicius@gmail.com> 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.
>>
>> This is my first patch, below the 15 line threshold.
>
> Seems good AFAICS.
>
> Do you often use orgmode, BABEL and sql all together ? (just curious
> as I am a DBA in real life).

I am not a DBA by trade, it is just that I found out that
developing web app features this way is more structured than keeping
SQL plus the rest of the code all over the filesystem when prototyping.

But then I use it to do a 'show processlist' on my SQL servers with a
C-c C-c which is always pleasant, but it is probably not what real DBAs
for monitoring..

>
> -- Xavier.

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

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

* Re: [PATCH] lisp/ob-sql.el: add support for :dbport parameter
  2015-04-07  6:17 ` Nicolas Goaziou
@ 2015-04-07 17:36   ` Saulius Menkevičius
  2015-04-07 20:27     ` Nicolas Goaziou
  0 siblings, 1 reply; 6+ messages in thread
From: Saulius Menkevičius @ 2015-04-07 17:36 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: emacs-orgmode, Saulius Menkevičius

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


Nicolas Goaziou writes:

> Hello,
>
> Saulius Menkevičius <saulius.menkevicius@gmail.com> 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?= <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.
>
> 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.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Patch for lips/ob-sql.el to support database port number --]
[-- Type: text/x-patch, Size: 2694 bytes --]

From e6d7585c4eaba775a370d40135ae8725c04751c8 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 (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


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



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

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

* Re: [PATCH] lisp/ob-sql.el: add support for :dbport parameter
  2015-04-07 17:36   ` Saulius Menkevičius
@ 2015-04-07 20:27     ` Nicolas Goaziou
  0 siblings, 0 replies; 6+ messages in thread
From: Nicolas Goaziou @ 2015-04-07 20:27 UTC (permalink / raw)
  To: Saulius Menkevičius; +Cc: emacs-orgmode

Saulius Menkevičius <saulius.menkevicius@gmail.com> writes:

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

OK. I slightly changed this line.

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

The previous lines should use `assq', but that's not very important.

> Updated patch is attached to this mail.

Applied. Thank you.


Regards,

^ permalink raw reply	[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).