* [PATCH] Add support for prologue and epilogue in SQL code blocks
@ 2021-07-03 7:00 Rodrigo Morales
2021-07-03 13:26 ` Rodrigo Morales
0 siblings, 1 reply; 3+ messages in thread
From: Rodrigo Morales @ 2021-07-03 7:00 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 1393 bytes --]
I'm creating this patch because the prologue and epilogue header
arguments can be useful for SQL code blocks. For example, in PostgreSQL
:prologue can be used for setting the schema name where operations are
to be executed (see example below)
#+BEGIN_SRC org
* The foo schema
:PROPERTIES:
:HEADER-ARGS:SQL+: :engine postgres
:HEADER-ARGS:SQL+: :prologue "SET search_path = foo;"
:END:
The following code block shows the table in the =foo= schema.
,#+BEGIN_SRC sql
\dt;
,#+END_SRC
The following shows the tuples in the table =A=.
,#+BEGIN_SRC sql
SELECT * FROM A;
,#+END_SRC
The following shows the tuples in the table =B=.
,#+BEGIN_SRC sql
SELECT * FROM B;
,#+END_SRC
#+END_SRC
PS: This is the second time I'm creating a patch, so I would really
appreciate any feedback if I've done something wrong.
--
La información contenida en este e-mail y sus anexos es confidencial,
privilegiada y está dirigida exclusivamente a su destinatario, en
consecuencia, solo puede ser utilizada por aquel. Si usted no es el
destinatario original, no deberá examinar, usar, copiar o distribuir este
mensaje o la información que contiene. Si lo recibe por error, por favor
reenvíelo a la persona que se lo envió y elimínelo. Cualquier retención o
uso total o parcial no autorizada de este mensaje está estrictamente
prohibida y sancionada por ley.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-lisp-ob-sql.el-Add-support-for-prologue-and-epilogue.patch --]
[-- Type: text/x-patch, Size: 1030 bytes --]
From ed083bed92dcac258c9253cd34485c6cfe91eb6c Mon Sep 17 00:00:00 2001
From: Rodrigo Morales <rodrigo.morales@utec.edu.pe>
Date: Sat, 3 Jul 2021 01:53:44 -0500
Subject: [PATCH] lisp/ob-sql.el: Add support for :prologue and :epilogue
---
lisp/ob-sql.el | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/lisp/ob-sql.el b/lisp/ob-sql.el
index 6eae5bb67..667bada31 100644
--- a/lisp/ob-sql.el
+++ b/lisp/ob-sql.el
@@ -93,8 +93,15 @@
(defun org-babel-expand-body:sql (body params)
"Expand BODY according to the values of PARAMS."
- (org-babel-sql-expand-vars
- body (org-babel--get-vars params)))
+ (let ((prologue (cdr (assq :prologue params)))
+ (epilogue (cdr (assq :epilogue params))))
+ (mapconcat 'identity
+ (list
+ prologue
+ (org-babel-sql-expand-vars
+ body (org-babel--get-vars params))
+ epilogue)
+ "\n")))
(defun org-babel-edit-prep:sql (info)
"Set `sql-product' in Org edit buffer.
--
2.32.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] Add support for prologue and epilogue in SQL code blocks
2021-07-03 7:00 [PATCH] Add support for prologue and epilogue in SQL code blocks Rodrigo Morales
@ 2021-07-03 13:26 ` Rodrigo Morales
2021-09-26 5:53 ` Bastien
0 siblings, 1 reply; 3+ messages in thread
From: Rodrigo Morales @ 2021-07-03 13:26 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 673 bytes --]
Apparently, A ">" character was accidentally inserted in the first line
of the patch. I'm attaching the patch again.
--
La información contenida en este e-mail y sus anexos es confidencial,
privilegiada y está dirigida exclusivamente a su destinatario, en
consecuencia, solo puede ser utilizada por aquel. Si usted no es el
destinatario original, no deberá examinar, usar, copiar o distribuir este
mensaje o la información que contiene. Si lo recibe por error, por favor
reenvíelo a la persona que se lo envió y elimínelo. Cualquier retención o
uso total o parcial no autorizada de este mensaje está estrictamente
prohibida y sancionada por ley.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-lisp-ob-sql.el-Add-support-for-prologue-and-epilogue.patch --]
[-- Type: text/x-patch, Size: 1030 bytes --]
From ed083bed92dcac258c9253cd34485c6cfe91eb6c Mon Sep 17 00:00:00 2001
From: Rodrigo Morales <rodrigo.morales@utec.edu.pe>
Date: Sat, 3 Jul 2021 01:53:44 -0500
Subject: [PATCH] lisp/ob-sql.el: Add support for :prologue and :epilogue
---
lisp/ob-sql.el | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/lisp/ob-sql.el b/lisp/ob-sql.el
index 6eae5bb67..667bada31 100644
--- a/lisp/ob-sql.el
+++ b/lisp/ob-sql.el
@@ -93,8 +93,15 @@
(defun org-babel-expand-body:sql (body params)
"Expand BODY according to the values of PARAMS."
- (org-babel-sql-expand-vars
- body (org-babel--get-vars params)))
+ (let ((prologue (cdr (assq :prologue params)))
+ (epilogue (cdr (assq :epilogue params))))
+ (mapconcat 'identity
+ (list
+ prologue
+ (org-babel-sql-expand-vars
+ body (org-babel--get-vars params))
+ epilogue)
+ "\n")))
(defun org-babel-edit-prep:sql (info)
"Set `sql-product' in Org edit buffer.
--
2.32.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-09-26 5:54 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-07-03 7:00 [PATCH] Add support for prologue and epilogue in SQL code blocks Rodrigo Morales
2021-07-03 13:26 ` Rodrigo Morales
2021-09-26 5:53 ` Bastien
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).