From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id SFqUHAdl1F4JPQAA0tVLHw (envelope-from ) for ; Mon, 01 Jun 2020 02:16:39 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id GDwMGAdl1F5zJQAAbx9fmQ (envelope-from ) for ; Mon, 01 Jun 2020 02:16:39 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 96734940145 for ; Mon, 1 Jun 2020 02:16:38 +0000 (UTC) Received: from localhost ([::1]:44728 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jfa0B-00052A-QU for larch@yhetil.org; Sun, 31 May 2020 22:16:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50126) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jfZzo-00051o-6l for emacs-orgmode@gnu.org; Sun, 31 May 2020 22:16:12 -0400 Received: from pb-smtp2.pobox.com ([64.147.108.71]:53930) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jfZzm-0002Qn-JC for emacs-orgmode@gnu.org; Sun, 31 May 2020 22:16:11 -0400 Received: from pb-smtp2.pobox.com (unknown [127.0.0.1]) by pb-smtp2.pobox.com (Postfix) with ESMTP id 0C5DD6B39B; Sun, 31 May 2020 22:16:08 -0400 (EDT) (envelope-from kyle@kyleam.com) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to:cc :subject:in-reply-to:references:date:message-id:mime-version :content-type; s=sasl; bh=yNaQf6QaKaYgBA3RZYNs0g107YY=; b=V0rln/ MalTCTFpPYEQRTwnEqWQWXY7m/bvk+Fs9sqQ0wJZyjIBsRULDWJvY/p9xKy0dZ8C iwMMRgsOkaZET++QJa5XFbJ/cWhgQnYJsGz09jXPjLl+aYEVOVArSMb7pOy6vZYj las0ruZ7TAG4M6S/xdaE3uxWJmPMz5JcxtlzM= Received: from pb-smtp2.nyi.icgroup.com (unknown [127.0.0.1]) by pb-smtp2.pobox.com (Postfix) with ESMTP id 04BF96B39A; Sun, 31 May 2020 22:16:08 -0400 (EDT) (envelope-from kyle@kyleam.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=kyleam.com; h=from:to:cc:subject:in-reply-to:references:date:message-id:mime-version:content-type; s=mesmtp; bh=klVOW7dXOQQsrXUdfeiGtZhublChYZoFSh2Nn3illys=; b=c/v7+qKKIXaHMOp/bhQqMGyp+IouluBTJF3rAwlaptqR26C6/zVuiOMk60YjypzI7HknCYonVR6fXmZPdXd2JScTO9hAyVaKdoWiiawOO0KEOLpAhmZNpWeiNx0euMWCKBCdQklaGHI/bTiJOh8ZK9MGkMtYxxF1GYqcex2ScJU= Received: from localhost (unknown [45.33.91.115]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp2.pobox.com (Postfix) with ESMTPSA id 7A2326B399; Sun, 31 May 2020 22:16:07 -0400 (EDT) (envelope-from kyle@kyleam.com) From: Kyle Meyer To: Daniel Kraus Subject: Re: [PATCH] ob-sql: Respect database param when using dbconnection In-Reply-To: <87a71s9jio.fsf@kraus.my> References: <87a71s9jio.fsf@kraus.my> Date: Mon, 01 Jun 2020 02:16:06 +0000 Message-ID: <87v9kbttsp.fsf@kyleam.com> MIME-Version: 1.0 Content-Type: text/plain X-Pobox-Relay-ID: DA49D1CC-A3AD-11EA-B2BC-D1361DBA3BAF-24757444!pb-smtp2.pobox.com Received-SPF: pass client-ip=64.147.108.71; envelope-from=kyle@kyleam.com; helo=pb-smtp2.pobox.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/31 20:19:46 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: stefano.rodighiero@gmail.com, emacs-orgmode@gnu.org Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Scanner: scn0 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=pobox.com header.s=sasl header.b=V0rln/ M; dkim=pass header.d=kyleam.com header.s=mesmtp header.b=c/v7+qKK; dmarc=none; spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Spam-Score: -1.21 X-TUID: 8ix0YCFQDDpA Daniel Kraus writes: > I use ob-sql with the :dbconnection param so I don't have my username and password in my org file. > But often I don't want to use the default database from the dbconnection alist but > rather specify it explicitly with :database. > Attached is a patch that fixes this. Thanks for the patch. > Subject: [PATCH] ob-sql: Respect database param when using dbconnection > > --- > lisp/ob-sql.el | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) Would you mind formatting your commit message as described at ? It'd also be good to have an ORG-NEWS entry for this, I think. > diff --git a/lisp/ob-sql.el b/lisp/ob-sql.el > index 7c359b988..d7a8bf0a0 100644 > --- a/lisp/ob-sql.el > +++ b/lisp/ob-sql.el > @@ -191,7 +191,8 @@ then look for the parameter 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) > + (if (and (assq :dbconnection params) > + (not (and (assq :database params) (eq name :database)))) > (let* ((dbconnection (cdr (assq :dbconnection params))) > (name-mapping '((:dbhost . sql-server) > (:dbport . sql-port) >From what I can gather from your description, this looks reasonable. I'm not an ob-sql user, so perhaps I missing something, but would it make sense for any connection parameter to take precedence if explicitly given in the source block header (i.e. something like the patch below)? [+cc Stefano, who added the :dbconneciton feature.] diff --git a/lisp/ob-sql.el b/lisp/ob-sql.el index 7c359b988..e7186938f 100644 --- a/lisp/ob-sql.el +++ b/lisp/ob-sql.el @@ -191,17 +191,17 @@ (defun org-babel-find-db-connection-param (params name) 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)))) + (or (cdr (assq name params)) + (and (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)))))))) (defun org-babel-execute:sql (body params) "Execute a block of Sql code with Babel.