[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/org fbbc8b55cf 4/4: ob-sql.el: Respect all params when
From: |
ELPA Syncer |
Subject: |
[elpa] externals/org fbbc8b55cf 4/4: ob-sql.el: Respect all params when using dbconnection |
Date: |
Mon, 31 Oct 2022 21:57:59 -0400 (EDT) |
branch: externals/org
commit fbbc8b55cf3a39c85f8576321ec560baf4d2331a
Author: Daniel Kraus <daniel@kraus.my>
Commit: Ihor Radchenko <yantar92@posteo.net>
ob-sql.el: Respect all params when using dbconnection
* etc/ORG-NEWS (Miscellaneous): Document the change.
* lisp/ob-sql.el (org-babel-find-db-connection-param): Make it
possible to overwrite parameters that are set from :dbconnection.
---
etc/ORG-NEWS | 14 ++++++++++++++
lisp/ob-sql.el | 24 ++++++++++++------------
2 files changed, 26 insertions(+), 12 deletions(-)
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 6e875deb62..b542da34be 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -457,6 +457,20 @@ The new variable name is =org-plantuml-args=. It now
applies to both
jar PlantUML file and executable.
** Miscellaneous
+*** SQL Babel ~:dbconnection~ parameter can be mixed with other SQL Babel
parameters
+
+Before you could either specify SQL parameters like ~:dbhost~,
+~:dbuser~, ~:database~, etc or a ~:dbconnection~ parameter which looks
+up all other parameters from the ~sql-connection-alist~ variable. Now
+it's possible to specify a ~:dbconnection~ and additionally other
+parameters that will add or overwrite the parameters coming from
+~sql-connection-alist~.
+
+E.g. if you have a connection in your ~sql-connection-alist~ to a
+server that has many databases, you don't need an entry for every
+database but instead can just specify ~:database~ next to your
+~:dbconnection~ parameter.
+
*** Post-processing code blocks can return an empty list
When the result of a regular code block is nil, then that was already
diff --git a/lisp/ob-sql.el b/lisp/ob-sql.el
index d1256bf83f..626d595c9f 100644
--- a/lisp/ob-sql.el
+++ b/lisp/ob-sql.el
@@ -222,18 +222,18 @@ then look for the parameter into the corresponding
connection
defined in `sql-connection-alist', otherwise look into PARAMS.
See `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)
- (:dbinstance . sql-dbinstance)
- (: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)
+ (:dbinstance . sql-dbinstance)
+ (: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.