From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id GK6+DFkL4GC4YwEAgWs5BA (envelope-from ) for ; Sat, 03 Jul 2021 09:01:45 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id 0C9wCFkL4GCxVAAAbx9fmQ (envelope-from ) for ; Sat, 03 Jul 2021 07:01:45 +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 4A3FD1779F for ; Sat, 3 Jul 2021 09:01:44 +0200 (CEST) Received: from localhost ([::1]:60998 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lzZeo-0004HB-Us for larch@yhetil.org; Sat, 03 Jul 2021 03:01:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51362) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lzZdX-0004G7-Vx for emacs-orgmode@gnu.org; Sat, 03 Jul 2021 03:00:24 -0400 Received: from mail-pj1-x102c.google.com ([2607:f8b0:4864:20::102c]:34529) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lzZdT-0008JP-Eh for emacs-orgmode@gnu.org; Sat, 03 Jul 2021 03:00:23 -0400 Received: by mail-pj1-x102c.google.com with SMTP id g6-20020a17090adac6b029015d1a9a6f1aso8967471pjx.1 for ; Sat, 03 Jul 2021 00:00:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=utec-edu-pe.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:mime-version; bh=gij9zkyawoNjauiMn7DKDM1fNlO1eqWP8vqq2JYxj5Q=; b=FEIM0/7qOmh1a+cIt1ylsqJq95k3BQ+SNGAnotTfTrecQj3LP7+r9RUVohaI9CsF8E IBX8Lsj3cbhNbd/Q57ogLFbkSwit8XE72Oe0HjGMEQ6Aqf5qmYRzWqzkrLhitJKGh24R 2gfaGYAO+JdlpEeacucdEamZAVH6o64U+c3KCwjByKssoU6VFH2Z18JtdgXaI1AGvCpx yRS33mv748kL2WdJ6v8QfkFZCewCEjq4M71eUpVLHy0YxgDtP7yxFWJvTS6BiID0oaO1 eTw4N7mOsgmtbmqyn9hDPSo3RoIpdEtBb7xP1/yKbSrBIMdoGPb+NABvbUcUjGZXSkub bPxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version; bh=gij9zkyawoNjauiMn7DKDM1fNlO1eqWP8vqq2JYxj5Q=; b=bQGwETgT0YM9X2m1YM62SwvgfxWP12bnq9gQPz2p7jgfN9Lf/hIT500s3RLA8CqQzB hXeVOiFVj08W0gVQqw0yDVK2L3JG+oQQi3HLitq8KFFCfxi8gLH5va8c6jQG0mblsy+w EzHY1arFjTiQHkoDpaxVkqWLJG2kh/qcGyJtMrZkenai1byo/ZRjbYvSyLCp8qevCX+/ 6YOv8doL+aTVcQZpu+PpbxgdstzGrdSje5GxqVQ2WcmYcqtwjhCOkbLPQWAA4CtWH5NS Vxv/V9bMU6o8bmQUlD2JKwl4vQVuGqAsuiyS+t9jWvIE418MM1Zt5bmb9Go8ZZ+X77KE krIw== X-Gm-Message-State: AOAM5338XTs3Tuf9l5Fi7DLTlREEPcAwaHYfSCyK4q8gEXInNwwiUcLT ANyaySjXlZ6A/0bCeYn3O1YDiajK57n6cY0oD53rMJeiJLCbH/JUsvmE9yTnGmJpIKX0dKmnOk5 KAVfmddaTcm3ZWzY64dw= X-Google-Smtp-Source: ABdhPJxqpvbab9oSYH0Z1yWamVy8EI9fGjLqZPnqO/fNuIb7VTeAcXy6oAje2qwXtOeNx7/Xp661vQ== X-Received: by 2002:a17:902:d486:b029:129:3d44:d168 with SMTP id c6-20020a170902d486b02901293d44d168mr3046163plg.30.1625295615630; Sat, 03 Jul 2021 00:00:15 -0700 (PDT) Received: from r1 ([190.239.232.58]) by smtp.gmail.com with ESMTPSA id t10sm4776872pgv.52.2021.07.03.00.00.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 Jul 2021 00:00:15 -0700 (PDT) From: Rodrigo Morales To: emacs-orgmode@gnu.org Subject: [PATCH] Add support for prologue and epilogue in SQL code blocks Date: Sat, 03 Jul 2021 02:00:07 -0500 Message-ID: <87h7hb51c8.fsf@utec.edu.pe> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=2607:f8b0:4864:20::102c; envelope-from=rodrigo.morales@utec.edu.pe; helo=mail-pj1-x102c.google.com X-Spam_score_int: 8 X-Spam_score: 0.8 X-Spam_bar: / X-Spam_report: (0.8 / 5.0 requ) BAYES_50=0.8, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no 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: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1625295704; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=gij9zkyawoNjauiMn7DKDM1fNlO1eqWP8vqq2JYxj5Q=; b=KKsKBUsy8j4sUG+4Mo3WVo6XZAkvLM5kdTL/aHROaDo8b0vcYM7uEZ1hg2asFAKmeU16pD UdENXEHWHcR50DkFwrzZ7pjIwfMOg0vn5PtSQ+jJxne1QWLUgsbFDQJ9eEhbrDCFiSALIa RxtEbziTlFO1MVTeiYg2O5VKsVYKgZNOfO32hZ8mufRDOh/08Uuu/geZSIDE8+ysfgdWXr xZqv0NNtvgbBY9A7I9V2nUqTM8LcsUGrwrJOl1QiAOVVc9RSD+Y7I6cpBxKPEcUMADwmln KL9Tt5L9xOWiQSFgIoQk9BRTv/32+1DwbTjDeoKy4f0iZx8ZBA5Jo4qttW2bZw== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1625295704; a=rsa-sha256; cv=none; b=APoaEnSSMOcfegndIFAGZP3dd6Coz8My01DBvFkQj6hgDbYHVi8rHPto3lSA3I6j/QyH5i QFn55X1NAyMkJ1cYk+Vp5Rf2LLU8UtyKmikgTJo/GvCy2x7jcmOgR5aZ+kQkGMDghf0uni wdMQw6eNDSc3XVAcd1TImZ7pAwyZOcjKKHgJRRK2rI+Nfa4kdPm/ToTpIOI4A4x5f68VCF cpUQCPIjeIF8KqsysHSvzejL3v/5ZgFq9ZIxd4MHsBHlyYkXqBJ81vyFvN94A8zskZ+smq iI2J292ApV9cXR63l5sgYUq5TXksYrxMN77HzLvWYNY1pJ6vwKJ2e2sXsz8PSg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=utec-edu-pe.20150623.gappssmtp.com header.s=20150623 header.b="FEIM0/7q"; 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-Migadu-Spam-Score: -2.61 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=utec-edu-pe.20150623.gappssmtp.com header.s=20150623 header.b="FEIM0/7q"; 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-Migadu-Queue-Id: 4A3FD1779F X-Spam-Score: -2.61 X-Migadu-Scanner: scn1.migadu.com X-TUID: KZZd1dYJ+HH5 --=-=-= Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: quoted-printable 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 =3D foo;" :END: The following code block shows the table in the =3Dfoo=3D schema. ,#+BEGIN_SRC sql \dt; ,#+END_SRC The following shows the tuples in the table =3DA=3D. ,#+BEGIN_SRC sql SELECT * FROM A; ,#+END_SRC The following shows the tuples in the table =3DB=3D. ,#+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. --=20 La informaci=F3n contenida en este e-mail y sus anexos es confidencial,=20 privilegiada y est=E1 dirigida exclusivamente a su destinatario, en=20 consecuencia, solo puede ser utilizada por aquel. Si usted no es el=20 destinatario original, no deber=E1 examinar, usar, copiar o distribuir este= =20 mensaje o la informaci=F3n que contiene. Si lo recibe por error, por favor= =20 reenv=EDelo a la persona que se lo envi=F3 y elim=EDnelo. Cualquier retenci= =F3n o=20 uso total o parcial no autorizada de este mensaje est=E1 estrictamente=20 prohibida y sancionada por ley. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-lisp-ob-sql.el-Add-support-for-prologue-and-epilogue.patch >From ed083bed92dcac258c9253cd34485c6cfe91eb6c Mon Sep 17 00:00:00 2001 From: Rodrigo Morales 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 --=-=-=--