all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* ob-sql dbconnection engine
@ 2023-01-21 12:20 Andreas Gerler
  2023-01-27 13:15 ` Ihor Radchenko
  0 siblings, 1 reply; 8+ messages in thread
From: Andreas Gerler @ 2023-01-21 12:20 UTC (permalink / raw)
  To: emacs-orgmode


[-- Attachment #1.1: Type: text/plain, Size: 232 bytes --]

Hi!

as I am still learning more elisp it took me some try and error but I can use the sql-product now within dbconnection.
Using :engine still works as well.
Still wondering if there is a more elegant way for the if clause.


[-- Attachment #1.2: ob-sql.el.diff --]
[-- Type: application/octet-stream, Size: 1768 bytes --]

diff --git a/lisp/ob-sql.el b/lisp/ob-sql.el
index f73e7003f..c6a192ae3 100644
--- a/lisp/ob-sql.el
+++ b/lisp/ob-sql.el
@@ -231,10 +231,14 @@ database connections."
                                   (:dbuser . sql-user)
                                   (:dbpassword . sql-password)
                                   (:dbinstance . sql-dbinstance)
-                                  (:database . sql-database)))
+                                  (:database . sql-database)
+                                  (:engine . sql-product)))
                   (mapped-name (cdr (assq name name-mapping))))
-             (cadr (assq mapped-name
-                         (cdr (assoc-string dbconnection sql-connection-alist t))))))))
+             (if (string-equal ":engine" name)
+                 (symbol-name (cadr (cadr (assq mapped-name
+                                   (cdr (assoc-string dbconnection sql-connection-alist t))))))
+               (cadr (assq mapped-name
+                           (cdr (assoc-string dbconnection sql-connection-alist t)))))))))
 
 (defun org-babel-execute:sql (body params)
   "Execute a block of Sql code with Babel.
@@ -247,7 +251,7 @@ This function is called by `org-babel-execute-src-block'."
          (dbpassword (org-babel-find-db-connection-param params :dbpassword))
          (dbinstance (org-babel-find-db-connection-param params :dbinstance))
          (database (org-babel-find-db-connection-param params :database))
-         (engine (cdr (assq :engine params)))
+         (engine  (org-babel-find-db-connection-param params :engine))
          (colnames-p (not (equal "no" (cdr (assq :colnames params)))))
          (in-file (org-babel-temp-file "sql-in-"))
          (out-file (or (cdr (assq :out-file params))

[-- Attachment #1.3: Type: text/plain, Size: 88 bytes --]



so long…

Andreas Gerler

—

http://www.bundesbrandschatzamt.de/~baron


[-- Attachment #2: Message signed with OpenPGP --]
[-- Type: application/pgp-signature, Size: 874 bytes --]

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

* Re: ob-sql dbconnection engine
  2023-01-21 12:20 ob-sql dbconnection engine Andreas Gerler
@ 2023-01-27 13:15 ` Ihor Radchenko
  2023-01-28 12:57   ` Andreas Gerler
  0 siblings, 1 reply; 8+ messages in thread
From: Ihor Radchenko @ 2023-01-27 13:15 UTC (permalink / raw)
  To: Andreas Gerler; +Cc: emacs-orgmode

Andreas Gerler <baron@bundesbrandschatzamt.de> writes:

> as I am still learning more elisp it took me some try and error but I can use the sql-product now within dbconnection.
> Using :engine still works as well.
> Still wondering if there is a more elegant way for the if clause.

Thanks for the patch!
Could you please explain in more details what the patch does?

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


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

* Re: ob-sql dbconnection engine
  2023-01-27 13:15 ` Ihor Radchenko
@ 2023-01-28 12:57   ` Andreas Gerler
  2023-01-28 14:15     ` Andreas Gerler
  2023-02-05 10:57     ` Ihor Radchenko
  0 siblings, 2 replies; 8+ messages in thread
From: Andreas Gerler @ 2023-01-28 12:57 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: emacs-orgmode

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

Hi!

without the patch your org source block has to look like:

#+begin_src sql :engine mysql :dbconnection mysqldb1
  SELECT * FROM nodes;
#+end_src

with that patch you can just type

#+begin_src sql :dbconnection mysqldb1
  SELECT * FROM nodes;
#+end_src

because your engine is mapped to sql-product in your sql-connection-alist:

(setq sql-connection-alist
      '((mysqldb1 (sql-product 'mysql)
                (sql-server "10.10.42.1")
                (sql-user "dbadmin")
                (sql-password "foo")
                (sql-database "testdb"))))


> On 27. Jan 2023, at 14:15, Ihor Radchenko <yantar92@posteo.net> wrote:
> 
> Andreas Gerler <baron@bundesbrandschatzamt.de> writes:
> 
>> as I am still learning more elisp it took me some try and error but I can use the sql-product now within dbconnection.
>> Using :engine still works as well.
>> Still wondering if there is a more elegant way for the if clause.
> 
> Thanks for the patch!
> Could you please explain in more details what the patch does?
> 
> --
> Ihor Radchenko // yantar92,
> Org mode contributor,
> Learn more about Org mode at <https://orgmode.org/>.
> Support Org development at <https://liberapay.com/org-mode>,
> or support my work at <https://liberapay.com/yantar92>
> 



so long…

Andreas Gerler

—

http://www.bundesbrandschatzamt.de/~baron

[-- Attachment #2: Message signed with OpenPGP --]
[-- Type: application/pgp-signature, Size: 874 bytes --]

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

* Re: ob-sql dbconnection engine
  2023-01-28 12:57   ` Andreas Gerler
@ 2023-01-28 14:15     ` Andreas Gerler
  2023-02-05 10:57     ` Ihor Radchenko
  1 sibling, 0 replies; 8+ messages in thread
From: Andreas Gerler @ 2023-01-28 14:15 UTC (permalink / raw)
  To: emacs-orgmode


[-- Attachment #1.1: Type: text/plain, Size: 50 bytes --]

Hi!

and a new patch with proper commit message.


[-- Attachment #1.2: 0002-lisp-ob-sql.el-sql-connection-alist-engine.patch --]
[-- Type: application/octet-stream, Size: 2312 bytes --]

From 98c5f83ae289252610be8ce80452fad97f6433c7 Mon Sep 17 00:00:00 2001
From: Andreas Gerler <baron@bundesbrandschatzamt.de>
Date: Sat, 28 Jan 2023 14:49:02 +0100
Subject: [PATCH 2/2] lisp/ob-sql.el: sql-connection-alist engine

* ob-sql.el (org-babel-find-db-connection-param): with dbconnection use
sql-product for engine parameter.

Signed-off-by: Andreas Gerler <baron@bundesbrandschatzamt.de>
---
 lisp/ob-sql.el | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/lisp/ob-sql.el b/lisp/ob-sql.el
index f73e7003f..c6a192ae3 100644
--- a/lisp/ob-sql.el
+++ b/lisp/ob-sql.el
@@ -231,10 +231,14 @@ database connections."
                                   (:dbuser . sql-user)
                                   (:dbpassword . sql-password)
                                   (:dbinstance . sql-dbinstance)
-                                  (:database . sql-database)))
+                                  (:database . sql-database)
+                                  (:engine . sql-product)))
                   (mapped-name (cdr (assq name name-mapping))))
-             (cadr (assq mapped-name
-                         (cdr (assoc-string dbconnection sql-connection-alist t))))))))
+             (if (string-equal ":engine" name)
+                 (symbol-name (cadr (cadr (assq mapped-name
+                                   (cdr (assoc-string dbconnection sql-connection-alist t))))))
+               (cadr (assq mapped-name
+                           (cdr (assoc-string dbconnection sql-connection-alist t)))))))))
 
 (defun org-babel-execute:sql (body params)
   "Execute a block of Sql code with Babel.
@@ -247,7 +251,7 @@ This function is called by `org-babel-execute-src-block'."
          (dbpassword (org-babel-find-db-connection-param params :dbpassword))
          (dbinstance (org-babel-find-db-connection-param params :dbinstance))
          (database (org-babel-find-db-connection-param params :database))
-         (engine (cdr (assq :engine params)))
+         (engine  (org-babel-find-db-connection-param params :engine))
          (colnames-p (not (equal "no" (cdr (assq :colnames params)))))
          (in-file (org-babel-temp-file "sql-in-"))
          (out-file (or (cdr (assq :out-file params))
-- 
2.39.0


[-- Attachment #1.3: Type: text/plain, Size: 1561 bytes --]



> On 28. Jan 2023, at 13:57, Andreas Gerler <baron@bundesbrandschatzamt.de> wrote:
> 
> Hi!
> 
> without the patch your org source block has to look like:
> 
> #+begin_src sql :engine mysql :dbconnection mysqldb1
>  SELECT * FROM nodes;
> #+end_src
> 
> with that patch you can just type
> 
> #+begin_src sql :dbconnection mysqldb1
>  SELECT * FROM nodes;
> #+end_src
> 
> because your engine is mapped to sql-product in your sql-connection-alist:
> 
> (setq sql-connection-alist
>      '((mysqldb1 (sql-product 'mysql)
>                (sql-server "10.10.42.1")
>                (sql-user "dbadmin")
>                (sql-password "foo")
>                (sql-database "testdb"))))
> 
> 
>> On 27. Jan 2023, at 14:15, Ihor Radchenko <yantar92@posteo.net> wrote:
>> 
>> Andreas Gerler <baron@bundesbrandschatzamt.de> writes:
>> 
>>> as I am still learning more elisp it took me some try and error but I can use the sql-product now within dbconnection.
>>> Using :engine still works as well.
>>> Still wondering if there is a more elegant way for the if clause.
>> 
>> Thanks for the patch!
>> Could you please explain in more details what the patch does?
>> 
>> --
>> Ihor Radchenko // yantar92,
>> Org mode contributor,
>> Learn more about Org mode at <https://orgmode.org/>.
>> Support Org development at <https://liberapay.com/org-mode>,
>> or support my work at <https://liberapay.com/yantar92>
>> 
> 
> 
> 
> so long…
> 
> Andreas Gerler
> 
> —
> 
> http://www.bundesbrandschatzamt.de/~baron


[-- Attachment #2: Message signed with OpenPGP --]
[-- Type: application/pgp-signature, Size: 874 bytes --]

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

* Re: ob-sql dbconnection engine
  2023-01-28 12:57   ` Andreas Gerler
  2023-01-28 14:15     ` Andreas Gerler
@ 2023-02-05 10:57     ` Ihor Radchenko
  2023-02-08 15:28       ` Andreas Gerler
  1 sibling, 1 reply; 8+ messages in thread
From: Ihor Radchenko @ 2023-02-05 10:57 UTC (permalink / raw)
  To: Andreas Gerler; +Cc: emacs-orgmode

Andreas Gerler <baron@bundesbrandschatzamt.de> writes:

> without the patch your org source block has to look like:
>
> #+begin_src sql :engine mysql :dbconnection mysqldb1
>   SELECT * FROM nodes;
> #+end_src
>
> with that patch you can just type
>
> #+begin_src sql :dbconnection mysqldb1
>   SELECT * FROM nodes;
> #+end_src
>
> because your engine is mapped to sql-product in your sql-connection-alist:
>
> (setq sql-connection-alist
>       '((mysqldb1 (sql-product 'mysql)
>                 (sql-server "10.10.42.1")
>                 (sql-user "dbadmin")
>                 (sql-password "foo")
>                 (sql-database "testdb"))))

Thanks for the explanation!
This logic assumes that engine names in ob-sql are the same with
products in `sql-product-alist'. Which is not true. For example, ob-sql
has postgresql while `sql-product-alist' has postgres.

Further, some engines are in ob-sql but not in sql.el and vice versa.

In order to provide auto-detection of sql engine we should first
synchronize the engine names.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


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

* Re: ob-sql dbconnection engine
  2023-02-05 10:57     ` Ihor Radchenko
@ 2023-02-08 15:28       ` Andreas Gerler
  2023-02-09 11:16         ` Ihor Radchenko
  0 siblings, 1 reply; 8+ messages in thread
From: Andreas Gerler @ 2023-02-08 15:28 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: emacs-orgmode

Hi Ihor,

I use only MySQL, PostgreSQL and Vertica.
However for me sql-product postgres in my sql-connection-alist works both in ob-sql as well as SQLi.
In the end you are still able to overwrite in your src block parameters via :engine

Andy

> On Feb 5, 2023, at 11:58 AM, Ihor Radchenko <yantar92@posteo.net> wrote:
> 
> Andreas Gerler <baron@bundesbrandschatzamt.de> writes:
> 
>> without the patch your org source block has to look like:
>> 
>> #+begin_src sql :engine mysql :dbconnection mysqldb1
>>  SELECT * FROM nodes;
>> #+end_src
>> 
>> with that patch you can just type
>> 
>> #+begin_src sql :dbconnection mysqldb1
>>  SELECT * FROM nodes;
>> #+end_src
>> 
>> because your engine is mapped to sql-product in your sql-connection-alist:
>> 
>> (setq sql-connection-alist
>>      '((mysqldb1 (sql-product 'mysql)
>>                (sql-server "10.10.42.1")
>>                (sql-user "dbadmin")
>>                (sql-password "foo")
>>                (sql-database "testdb"))))
> 
> Thanks for the explanation!
> This logic assumes that engine names in ob-sql are the same with
> products in `sql-product-alist'. Which is not true. For example, ob-sql
> has postgresql while `sql-product-alist' has postgres.
> 
> Further, some engines are in ob-sql but not in sql.el and vice versa.
> 
> In order to provide auto-detection of sql engine we should first
> synchronize the engine names.
> 
> -- 
> Ihor Radchenko // yantar92,
> Org mode contributor,
> Learn more about Org mode at <https://orgmode.org/>.
> Support Org development at <https://liberapay.com/org-mode>,
> or support my work at <https://liberapay.com/yantar92>
> 



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

* Re: ob-sql dbconnection engine
  2023-02-08 15:28       ` Andreas Gerler
@ 2023-02-09 11:16         ` Ihor Radchenko
  2023-10-07 10:51           ` Ihor Radchenko
  0 siblings, 1 reply; 8+ messages in thread
From: Ihor Radchenko @ 2023-02-09 11:16 UTC (permalink / raw)
  To: Andreas Gerler; +Cc: emacs-orgmode

Andreas Gerler <baron@bundesbrandschatzamt.de> writes:

> In the end you are still able to overwrite in your src block parameters via :engine

Sure, but wouldn't it be better to amend the patch adding aliases to the
supported engine names in `sql-connection-alist'?

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


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

* Re: ob-sql dbconnection engine
  2023-02-09 11:16         ` Ihor Radchenko
@ 2023-10-07 10:51           ` Ihor Radchenko
  0 siblings, 0 replies; 8+ messages in thread
From: Ihor Radchenko @ 2023-10-07 10:51 UTC (permalink / raw)
  To: Andreas Gerler; +Cc: emacs-orgmode

Ihor Radchenko <yantar92@posteo.net> writes:

> Andreas Gerler <baron@bundesbrandschatzamt.de> writes:
>
>> In the end you are still able to overwrite in your src block parameters via :engine
>
> Sure, but wouldn't it be better to amend the patch adding aliases to the
> supported engine names in `sql-connection-alist'?

I considered merging and possibly amending the patch one more time, but
it appears that the proposed approach has another major downside of
ignoring :engine header argument completely. Due to non-triviality of
the merge and absence of followup from the patch author, I am closing
this feature request.

Canceled.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


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

end of thread, other threads:[~2023-10-07 10:55 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-01-21 12:20 ob-sql dbconnection engine Andreas Gerler
2023-01-27 13:15 ` Ihor Radchenko
2023-01-28 12:57   ` Andreas Gerler
2023-01-28 14:15     ` Andreas Gerler
2023-02-05 10:57     ` Ihor Radchenko
2023-02-08 15:28       ` Andreas Gerler
2023-02-09 11:16         ` Ihor Radchenko
2023-10-07 10:51           ` Ihor Radchenko

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.