emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Nicolas Goaziou <mail@nicolasgoaziou.fr>
To: Stefano Rodighiero <stefano.rodighiero@gmail.com>
Cc: emacs-orgmode@gnu.org
Subject: Re: [PATCH] ob-sql.el: Option to reference connections in `sql-connection-alist'
Date: Sun, 07 Apr 2019 09:24:26 +0200	[thread overview]
Message-ID: <87sguu5lcl.fsf@nicolasgoaziou.fr> (raw)
In-Reply-To: <CABuLN4xk8jYhC6yhiEzd7_aZpeHXnSt+t6QMCzVcgNB478drSg@mail.gmail.com> (Stefano Rodighiero's message of "Sun, 24 Mar 2019 13:04:33 +0100")

Hello,

Stefano Rodighiero <stefano.rodighiero@gmail.com> writes:

> [This is the first patch I ever submitted.

Thank you. Some comments follow.

> I hope it complies with
> your standards: if it does not, I'll be happy to work on it until it's
> fine.  I am not sure it qualifies as a tiny change.]

It does.

> Subject: [PATCH] ob-sql.el: Option to reference connections in
>  `sql-connection-alist'
>
> * ob-sql.el: Provide a new param called :dbconnection, that can be
> used to reference connections defined in `sql-connection-alist', a
> custom variable defined in sql.el.

You need to spell out the new function in the commit message:

* ob-sql.el (org-babel-find-db-connection-param): new function.

This patch provides a new parameter :dbconnection, ...

> +(defun org-babel-find-db-connection-param (params name)
> +  "Return db connection param NAME.

database, parameter

> +Given a param NAME, if :dbconnection is defined in PARAMS then
> +look for the param into the corresponding connection defined in
> +`sql-connection-alist`, otherwise look into PARAMS.  Look
> +`sql-connection-alist` (part of SQL mode) for how to define
> +database connections."
> +  (if (assq :dbconnection params)
> +      (let* ((dbconnection (cdr (assq :dbconnection params)))
> +             (name-mapping '((dbhost . sql-server)
> +                             (dbport . sql-port)
> +                             (dbuser . sql-user)
> +                             (dbpassword . sql-password)
> +                             (database . sql-database)))
> +             (mapped-name (cdr (assq name name-mapping))))
> +        (cadr (assq mapped-name
> +                    (cdr (assoc dbconnection
> +                                sql-connection-alist)))))
> +    (cdr (assq name params))))

Isn't there a type mismatch here? 
> +
>  (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'."
>    (let* ((result-params (cdr (assq :result-params params)))
>           (cmdline (cdr (assq :cmdline params)))
> -         (dbhost (cdr (assq :dbhost params)))
> -         (dbport (cdr (assq :dbport params)))
> -         (dbuser (cdr (assq :dbuser params)))
> -         (dbpassword (cdr (assq :dbpassword params)))
> -         (database (cdr (assq :database params)))
> +         (dbhost (org-babel-find-db-connection-param params 'dbhost))
> +         (dbport (org-babel-find-db-connection-param params 'dbport))
> +         (dbuser (org-babel-find-db-connection-param params 'dbuser))
> +         (dbpassword (org-babel-find-db-connection-param params 'dbpassword))
> +         (database (org-babel-find-db-connection-param params 'database))
>           (engine (cdr (assq :engine params)))

The change from keywords to plain symbols is slightly confusing. Could
`org-babel-find-db-connection-param' use keywords instead? This is the
usual format for parameters in Babel.

Regards,

-- 
Nicolas Goaziou

  reply	other threads:[~2019-04-07  7:24 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-24 12:04 [PATCH] ob-sql.el: Option to reference connections in `sql-connection-alist' Stefano Rodighiero
2019-04-07  7:24 ` Nicolas Goaziou [this message]
2019-04-14 14:25   ` Stefano Rodighiero
2019-04-15 16:11     ` Nicolas Goaziou
2019-04-15 20:16       ` Stefano Rodighiero
2019-04-17 12:26         ` Nicolas Goaziou
2019-04-17 13:34         ` stardiviner

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=87sguu5lcl.fsf@nicolasgoaziou.fr \
    --to=mail@nicolasgoaziou.fr \
    --cc=emacs-orgmode@gnu.org \
    --cc=stefano.rodighiero@gmail.com \
    /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).