From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id QHmjDEWMP2D9DAAA0tVLHw (envelope-from ) for ; Wed, 03 Mar 2021 13:16:53 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id UOSGCEWMP2DZUQAA1q6Kng (envelope-from ) for ; Wed, 03 Mar 2021 13:16:53 +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 4C00A2725D for ; Wed, 3 Mar 2021 14:16:52 +0100 (CET) Received: from localhost ([::1]:55376 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lHRMw-0003BC-IB for larch@yhetil.org; Wed, 03 Mar 2021 08:16:50 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:48644) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lHRMT-0003Ak-Fa for emacs-orgmode@gnu.org; Wed, 03 Mar 2021 08:16:21 -0500 Received: from out2-smtp.messagingengine.com ([66.111.4.26]:40417) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lHRMR-0007sI-Jd for emacs-orgmode@gnu.org; Wed, 03 Mar 2021 08:16:21 -0500 Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.nyi.internal (Postfix) with ESMTP id 1A6475C0056 for ; Wed, 3 Mar 2021 08:16:18 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Wed, 03 Mar 2021 08:16:18 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-type:date:from:message-id :mime-version:subject:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm2; bh=GnwuEFPCu5uRuAoTst6HDlAlWCYFF 7tVStIPqMyHLCo=; b=S1Hkr7gRLxEsIiSdpzxr4brPQgD6YbF91c3XHykKLDWgV 5RAIMSAY95CPHqNj3i+SsR+ZxWCNBpBbBJaXx7V2PITgl73pKIbanQbkG8GDmbMP UJyGeTspOAKfYdNhW2W9/cr5siPXAMGYz6oHhXRNEi6QOcR0N8o6j1ao9YlfcmuN lWPZ32ZweIdSEafUhO0HTO8/RyDusKNQ7OkV/3Oq3nDEjWfT3Sho4hyIN2/5jbt+ Jcg5QLwFDM2ETXxPbePxAV+ESh9waYisVLOAxss0zmGOK1MmHqBb2Ha4dyJZrMLs FbCM2qtsFvcKv0M7FnjPG2VcsRBBM3pK8oX5RWPxA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledruddtvddgheduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefvhffukffffgggtgesmhdtreertd efjeenucfhrhhomheppfhitghkucfurghvrghgvgcuoehnihgtkhesnhhitghkshgrvhgr ghgvrdgtrgeqnecuggftrfgrthhtvghrnhepleeiteegfeejteejgedvtdeugfejffetle fgleetheevieduieegleefffeuvdefnecukfhppeejtddrhedvrddvgedrudekudenucev lhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehnihgtkhesnh hitghkshgrvhgrghgvrdgtrg X-ME-Proxy: Received: from [192.168.0.67] (bras-base-aylmpq0104w-grc-16-70-52-24-181.dsl.bell.ca [70.52.24.181]) by mail.messagingengine.com (Postfix) with ESMTPA id BD27D1080059 for ; Wed, 3 Mar 2021 08:16:17 -0500 (EST) To: emacs-orgmode@gnu.org From: Nick Savage Subject: [PATCH] Reduce code duplication in ob-sql.el and ob-sqlite.el Message-ID: <0766206a-5df8-8d95-e6fd-2f96f06c9840@nicksavage.ca> Date: Wed, 3 Mar 2021 08:16:17 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.0 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------F799E2D8F96E8EDFC29B9196" Content-Language: en-US Received-SPF: none client-ip=66.111.4.26; envelope-from=nick@nicksavage.ca; helo=out2-smtp.messagingengine.com X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_NONE=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=1614777412; 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=GnwuEFPCu5uRuAoTst6HDlAlWCYFF7tVStIPqMyHLCo=; b=RV7ocJDgSpfqylTYZBIVnOxq290xVHJfKTa9A9lm7ZHH/NESs07Q1AgMybEdI2+BW24N56 QLLlkYA+6WJ2zBmBXbudbgp6IJexh2uv1eJng7+7aXa54scMPbN/PyiIkcBqltgmm9sEds BgdMxrNJuFJ5acHxp66adhLvd5AziksVplWhxOcbihaxSNoOIrKXoqXVliuptypV+csrsT Txh6PvyrmyYzWNqgDmPwy5TiVZwQhdeUhmvfWFXHZIWrMDBD+G+KyLfuEpikseXdMNPOEQ afSbPv4Wynve7LXn2yVQSXIaYE51XqLb1CjPMT3h3HF8zvMmB9+AhD4mi0HzuQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1614777412; a=rsa-sha256; cv=none; b=Q/IsDUyflC0Nsgmix+udIEesgxpiLTvG2pQDeVwqLfbIXDG9J7xwhlpmuZ9t+HUTq1ThnP mRX2nycM+38yPFyMPdsPW8OmcOehzqKEHVxYVVpE6PT8IhaYJ8RUfX0uzxKWK5CXs9g64S BMw5Zk6NuVw1dJosCzl/oUCbimoHkd1Rbyf+rOWmzoWI78hNtNan/fEMiNkITxH5GvO4Ir 2nSQ09CfG1aVQruW9QzzVmeXkbM6L8SlvGR2X5Bd4zUrLZqMfG/ucvOWeaZ/LCdh5c/jjj kKszds6AJajSo8pD88wbVJ2eOnK6bgoGL5wyXuaHZHuu19mfmNiTWTWBQOQQig== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=messagingengine.com header.s=fm2 header.b=S1Hkr7gR; 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-Spam-Score: -2.56 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=messagingengine.com header.s=fm2 header.b=S1Hkr7gR; 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: 4C00A2725D X-Spam-Score: -2.56 X-Migadu-Scanner: scn0.migadu.com X-TUID: MUirAx7WUfnx This is a multi-part message in MIME format. --------------F799E2D8F96E8EDFC29B9196 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Hi everyone, See the attached patch. It is a small change to reduce code duplication between ob-sql.el and ob-sqlite.el by reusing org-babel-sql-expand-vars as suggested by the FIXME in ob-sqlite.el. Thanks, Nick --------------F799E2D8F96E8EDFC29B9196 Content-Type: text/x-patch; charset=UTF-8; name="0001-Reduce-code-duplication-in-ob-sqlite.el-and-ob-sql.e.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0001-Reduce-code-duplication-in-ob-sqlite.el-and-ob-sql.e.pa"; filename*1="tch" >From 849a1b7417b39abbf0aeb1b241e890470e4111cd Mon Sep 17 00:00:00 2001 From: Nicholas Savage Date: Wed, 3 Mar 2021 07:47:15 -0500 Subject: [PATCH] Reduce code duplication in ob-sqlite.el and ob-sql.el * lisp/ob-sqlite.el (org-babel-sqlite-expand-vars): removed function to replace with ob-sql.el version * lisp/ob-sql.el (org-babel-sql-expand-vars): updated to support expanding sqlite vars --- lisp/ob-sql.el | 15 +++++++++++---- lisp/ob-sqlite.el | 24 +++--------------------- 2 files changed, 14 insertions(+), 25 deletions(-) diff --git a/lisp/ob-sql.el b/lisp/ob-sql.el index 68d5ddd0a..b1c6920cb 100644 --- a/lisp/ob-sql.el +++ b/lisp/ob-sql.el @@ -350,8 +350,13 @@ SET COLSEP '|' (org-babel-pick-name (cdr (assq :rowname-names params)) (cdr (assq :rownames params)))))))) -(defun org-babel-sql-expand-vars (body vars) - "Expand the variables held in VARS in BODY." +(defun org-babel-sql-expand-vars (body vars &optional sqlite) + "Expand the variables held in VARS in BODY. + +If SQLITE has been provided, prevent passing a format to +`orgtbl-to-csv'. This prevents overriding the default format, which if +there were commas in the context of the table broke the table as an +argument mechanism." (mapc (lambda (pair) (setq body @@ -362,9 +367,11 @@ SET COLSEP '|' (let ((data-file (org-babel-temp-file "sql-data-"))) (with-temp-file data-file (insert (orgtbl-to-csv - val '(:fmt (lambda (el) (if (stringp el) + val (if sqlite + nil + '(:fmt (lambda (el) (if (stringp el) el - (format "%S" el))))))) + (format "%S" el)))))))) data-file) (if (stringp val) val (format "%S" val)))) body))) diff --git a/lisp/ob-sqlite.el b/lisp/ob-sqlite.el index 6e21fa9fd..2ec9deb78 100644 --- a/lisp/ob-sqlite.el +++ b/lisp/ob-sqlite.el @@ -27,6 +27,7 @@ ;;; Code: (require 'ob) +(require 'ob-sql) (declare-function org-table-convert-region "org-table" (beg0 end0 &optional separator)) @@ -51,8 +52,8 @@ (defun org-babel-expand-body:sqlite (body params) "Expand BODY according to the values of PARAMS." - (org-babel-sqlite-expand-vars - body (org-babel--get-vars params))) + (org-babel-sql-expand-vars + body (org-babel--get-vars params) t)) (defvar org-babel-sqlite3-command "sqlite3") @@ -110,25 +111,6 @@ This function is called by `org-babel-execute-src-block'." (org-babel-sqlite-offset-colnames (org-table-to-lisp) headers-p))))))) -(defun org-babel-sqlite-expand-vars (body vars) - "Expand the variables held in VARS in BODY." - ;; FIXME: Redundancy with org-babel-sql-expand-vars! - (mapc - (lambda (pair) - (setq body - (replace-regexp-in-string - (format "$%s" (car pair)) - (let ((val (cdr pair))) - (if (listp val) - (let ((data-file (org-babel-temp-file "sqlite-data-"))) - (with-temp-file data-file - (insert (orgtbl-to-csv val nil))) - data-file) - (if (stringp val) val (format "%S" val)))) - body))) - vars) - body) - (defun org-babel-sqlite-table-or-scalar (result) "If RESULT looks like a trivial table, then unwrap it." (if (and (equal 1 (length result)) -- 2.20.1 --------------F799E2D8F96E8EDFC29B9196--