Re: [O] [PATCH] Add support for :dbhost, :dbuser and :database parameters for poastgresql in ob-sql.el
Hello, Thomas S. Dye writes : If you'd like to contribute other patches, then you'll want to sign the FSF papers following the instructions here: http://orgmode.org/worg/org-contribute.html#sec-2 This process will probably take some weeks to complete. I completed the copyright assignment procedure, so I come back to propose my changes. To avoid you browsing your mails to find the first message, I summarize again the changes in this mail, and attach the patch to it. This patch adds support for :dbhost, :dbuser and :database parameters for SQL code blocks that uses postgresql engine. This allows to abstract postgresql login details instead of sending parameters in a psql-specific format using :cmdline argument. I am still at your service for any comment on the code. Regards, Steven Rémot From 6ad99759a16c8b6f9decfb8ea90c84e7a1c18fdc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steven=20R=C3=A9mot?= steven.re...@gmail.com Date: Fri, 8 Aug 2014 21:49:44 +0200 Subject: [PATCH] ob-sql.el: Enhance postgresql support * lisp/ob-sql.el: Add support for :dbhost, :dbuser and :database parameters in sql code blocks for postgresql engine. Before this patch, it was necessary to use :cmdline parameter to specify host, user and database different the the default ones. Now, this can be done using parameters that are independents of the engine used. This is not trivial (and not recommended) to pass password as a command line argument to psql, so :dbpassword is not supported. --- lisp/ob-sql.el | 12 +++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lisp/ob-sql.el b/lisp/ob-sql.el index 7b85df8..9fe9da2 100644 --- a/lisp/ob-sql.el +++ b/lisp/ob-sql.el @@ -87,6 +87,15 @@ (when password (concat -p password)) (when database (concat -D database)) +(defun dbstring-postgresql (host user database) + Make PostgreSQL command line ards for database connection. +Pass nil to omit that arg. + (combine-and-quote-strings + (remq nil + (list (when host (concat -h host)) + (when user (concat -U user)) + (when database (concat -d database)) + (defun org-babel-execute:sql (body params) Execute a block of Sql code with Babel. This function is called by `org-babel-execute-src-block'. @@ -123,8 +132,9 @@ This function is called by `org-babel-execute-src-block'. (org-babel-process-file-name in-file) (org-babel-process-file-name out-file))) ('postgresql (format - psql --set=\ON_ERROR_STOP=1\ %s -A -P footer=off -F \\t\ -f %s -o %s %s + psql --set=\ON_ERROR_STOP=1\ %s -A -P footer=off -F \\t\ %s -f %s -o %s %s (if colnames-p -t) + (dbstring-postgresql dbhost dbuser database) (org-babel-process-file-name in-file) (org-babel-process-file-name out-file) (or cmdline ))) -- 1.9.1
Re: [O] [PATCH] Add support for :dbhost, :dbuser and :database parameters for poastgresql in ob-sql.el
Hello, Steven Rémot steven.re...@gmail.com writes: This patch adds support for :dbhost, :dbuser and :database parameters for SQL code blocks that uses postgresql engine. This allows to abstract postgresql login details instead of sending parameters in a psql-specific format using :cmdline argument. Thanks for your patch. Some comments below. * lisp/ob-sql.el: Add support for :dbhost, :dbuser and :database parameters in sql code blocks for postgresql engine. It should be * lisp/ob-sql.el (dbstring-postgresql): New function (org-babel-execute:sql): Use new function. +(defun dbstring-postgresql (host user database) + Make PostgreSQL command line ards for database connection. args +Pass nil to omit that arg. + (combine-and-quote-strings + (remq nil + (list (when host (concat -h host)) +(when user (concat -U user)) +(when database (concat -d database)) + This is not related to your patch, but while you're at it, use `delq' instead of `remq' (nitpick) and `dbstring-postgresql' needs to be renamed `org-babel-sql-dbstring-postgresql' or some such. Regards, -- Nicolas Goaziou
Re: [O] [PATCH] Add support for :dbhost, :dbuser and :database parameters for poastgresql in ob-sql.el
Thank you for your comments. I attached the fixed patch below. On 09/20/2014 14:16, Nicolas Goaziou wrote: This is not related to your patch, but while you're at it, use `delq' instead of `remq' (nitpick) and `dbstring-postgresql' needs to be renamed `org-babel-sql-dbstring-postgresql' or some such. I used mysql parameters handling code as a template for writing my patch, so it suffered from the same problems. I added a second patch that renames `dbstring-mysql' to `org-babel-sql-dbstring-mysql' and that uses `delq' instead of `remq' in its implementation. I did some basic tests to ensure I didn't break anything. Regards, Steven Rémot From b4584bddcc66046836c4029ab992bd8b8ed347ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steven=20R=C3=A9mot?= steven.re...@gmail.com Date: Sat, 20 Sep 2014 15:02:36 +0200 Subject: [PATCH 1/2] ob-sql.el: Enhance postgresql support * lisp/ob-sql.el (org-babel-sql-dbstring-postgresql): New function (org-babel-execute:sql): Use new function. Before this patch, it was necessary to use :cmdline parameter to specify host, user and database different the the default ones. Now, this can be done using parameters that are independents of the engine used. This is not trivial (and not recommended) to pass password as a command line argument to psql, so :dbpassword is not supported. --- lisp/ob-sql.el | 12 +++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lisp/ob-sql.el b/lisp/ob-sql.el index 7b85df8..292d5dd 100644 --- a/lisp/ob-sql.el +++ b/lisp/ob-sql.el @@ -87,6 +87,15 @@ (when password (concat -p password)) (when database (concat -D database)) +(defun org-babel-sql-dbstring-postgresql (host 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 user (concat -U user)) + (when database (concat -d database)) + (defun org-babel-execute:sql (body params) Execute a block of Sql code with Babel. This function is called by `org-babel-execute-src-block'. @@ -123,8 +132,9 @@ This function is called by `org-babel-execute-src-block'. (org-babel-process-file-name in-file) (org-babel-process-file-name out-file))) ('postgresql (format - psql --set=\ON_ERROR_STOP=1\ %s -A -P footer=off -F \\t\ -f %s -o %s %s + psql --set=\ON_ERROR_STOP=1\ %s -A -P footer=off -F \\t\ %s -f %s -o %s %s (if colnames-p -t) + (org-babel-sql-dbstring-postgresql dbhost dbuser database) (org-babel-process-file-name in-file) (org-babel-process-file-name out-file) (or cmdline ))) -- 1.9.1 From 4cd3b02de74c74980ca0b99f7faa228f96792a47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steven=20R=C3=A9mot?= steven.re...@gmail.com Date: Sat, 20 Sep 2014 15:09:29 +0200 Subject: [PATCH 2/2] ob-sql.el: Clean mysql parameters generation * lisp/ob-sql.el (dbstring-mysql): Rename function and tweak a bit its implementation (org-babel-execute:sql): Use new function name Prefix `dbstring-mysql' function with the namespace org-babel-sql to avoid name collisions. Also replace the call to `remq' by `delq' because it is a bit more efficient, and also to be consistent with `org-babel-sql-dbstring-postgresql'. --- lisp/ob-sql.el | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lisp/ob-sql.el b/lisp/ob-sql.el index 292d5dd..493b3dc 100644 --- a/lisp/ob-sql.el +++ b/lisp/ob-sql.el @@ -78,10 +78,10 @@ (org-babel-sql-expand-vars body (mapcar #'cdr (org-babel-get-header params :var -(defun dbstring-mysql (host user password database) +(defun org-babel-sql-dbstring-mysql (host user password database) Make MySQL cmd line args for database connection. Pass nil to omit that arg. (combine-and-quote-strings - (remq nil + (delq nil (list (when host (concat -h host)) (when user (concat -u user)) (when password (concat -p password)) @@ -126,7 +126,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 -(dbstring-mysql dbhost dbuser dbpassword database) +(org-babel-sql-dbstring-mysql dbhost dbuser dbpassword database) (if colnames-p -N) (or cmdline ) (org-babel-process-file-name in-file) -- 1.9.1
Re: [O] [PATCH] Add support for :dbhost, :dbuser and :database parameters for poastgresql in ob-sql.el
Steven Rémot steven.re...@gmail.com writes: Thank you for your comments. I attached the fixed patch below. Applied. Thank you. Regards, -- Nicolas Goaziou
Re: [O] [PATCH] Add support for :dbhost, :dbuser and :database parameters for poastgresql in ob-sql.el
Le 09/08/2014 02:38, Thomas S. Dye a écrit : Aloha Steven, Steven Rémot steven.re...@gmail.com writes: Hi, I did some changes to support :dbname, :dbhost and :database in SQL code blocks when using postgresql engine. Even if it was possible to specify this information using :cmdline parameter, I thought it was a bit cleaner to be able to provide this information in a way independent from the command line. I will gladly accept any remark / comment on this patch. Regards, Steven Rémot I'm not certain who is maintaining ob-sql.el, so I'm not replying in any directly useful way. However, this patch looks straightforward and good to me. Have you signed FSF papers? If so, the maintainer can accept (or reject) your patch. If not, then you'll need to identify it as a tiny change (see http://orgmode.org/worg/org-contribute.html). Thanks for this contribution to Org mode. All the best, Tom This is my only contribution to Emacs code, and it changes only 12 lines that impact a very tiny fragment of org, so I though I could send it without signing papers. If I was wrong, I don't mind signing papers at all. Regards, Steven Rémot
Re: [O] [PATCH] Add support for :dbhost, :dbuser and :database parameters for poastgresql in ob-sql.el
Steven Rémot steven.re...@gmail.com writes: This is my only contribution to Emacs code, and it changes only 12 lines that impact a very tiny fragment of org, so I though I could send it without signing papers. If I was wrong, I don't mind signing papers at all. Either way should work. If you'd like to contribute other patches, then you'll want to sign the FSF papers following the instructions here: http://orgmode.org/worg/org-contribute.html#sec-2 This process will probably take some weeks to complete. This patch is less than 15 lines, so I think it can be considered a tiny change. If you want to contribute it as a tiny change then you'll need to indicate this in the patch. I'm not finding exact instructions for this at the moment, so someone else on the list will have to help. All the best, Tom -- T.S. Dye Colleagues, Archaeologists 735 Bishop St, Suite 315, Honolulu, HI 96813 Tel: 808-529-0866, Fax: 808-529-0884 http://www.tsdye.com
Re: [O] [PATCH] Add support for :dbhost, :dbuser and :database parameters for poastgresql in ob-sql.el
Le 09/08/2014 17:31, Thomas S. Dye a écrit : If you'd like to contribute other patches, then you'll want to sign the FSF papers following the instructions here: I think it won't be the only patch I send to Org mode or Emacs, so I will sign copyright assignment and come back when it is done. Thank you for the clarification! Regards, Steven Rémot
Re: [O] [PATCH] Add support for :dbhost, :dbuser and :database parameters for poastgresql in ob-sql.el
Aloha Steven, Steven Rémot steven.re...@gmail.com writes: Hi, I did some changes to support :dbname, :dbhost and :database in SQL code blocks when using postgresql engine. Even if it was possible to specify this information using :cmdline parameter, I thought it was a bit cleaner to be able to provide this information in a way independent from the command line. I will gladly accept any remark / comment on this patch. Regards, Steven Rémot I'm not certain who is maintaining ob-sql.el, so I'm not replying in any directly useful way. However, this patch looks straightforward and good to me. Have you signed FSF papers? If so, the maintainer can accept (or reject) your patch. If not, then you'll need to identify it as a tiny change (see http://orgmode.org/worg/org-contribute.html). Thanks for this contribution to Org mode. All the best, Tom -- Thomas S. Dye http://www.tsdye.com