From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1.migadu.com ([2001:41d0:303:e224::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms13.migadu.com with LMTPS id uD4qAmx0fWcLgAAA62LTzQ:P1 (envelope-from ) for ; Tue, 07 Jan 2025 18:37:32 +0000 Received: from aspmx1.migadu.com ([2001:41d0:303:e224::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1.migadu.com with LMTPS id uD4qAmx0fWcLgAAA62LTzQ (envelope-from ) for ; Tue, 07 Jan 2025 19:37:32 +0100 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=cCBe7nXy; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org"; dmarc=pass (policy=none) header.from=posteo.net ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1736275051; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=70zov4FZDIcN5llxihdtkraETzXmiX/PGA4Z/xL8+24=; b=Nw7MtB2Iu2m16rv/wGsO3YYpHMy0EpHB7LYbQICc3B4svCLLTGkWa897H3N41swBcbFsZK v6YfN4b9yGv416dVV0HmLy1Tvx0Qn0TL/wkP9M338xUI1P5+gUMjms1LdBtwZUyMoUVsHH MIz0/LG0HJNJlMtHLafbBWgQI36Os2E5Hb8q12GnOtZj17e68OZ6G2Y73hN5MClkcUUGas 36EQGnHmYC/ONhRsC9SJnxaaglOSAAT41ieD9bFlwxrQI1SU/DISskNl9gLOvajISn2d1O 8puDwXupZzWsGU3KxQ6GGfOAoiDv2CBbsccg39cCeV5/yjZwtHtFPYmi6UNMvQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=cCBe7nXy; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org"; dmarc=pass (policy=none) header.from=posteo.net ARC-Seal: i=1; s=key1; d=yhetil.org; t=1736275051; a=rsa-sha256; cv=none; b=jn/utTlIXhXnJ6xNgtCOVKBVKVZ/ooyi5Mo7OnfExilzitcHFSiIx5Z4Tv7oU8ATt3OXpn nuIb1nbNfjEho5tSK2zoXoWNJpws7dOd2XTmujtNppWhaMoTf03jg4XZIZAgsplncVWL+f EdLx3si7vYkpLsDS8ytiAIRZ2Ac7qIGNOVPwMhxG/ClC0608xR38FMyYUlBcaZDK3J5x4Q l8SedYx/TiFS1shyKlPjYH6IRMuURCZixzmzPSD1HNk2iqLVFdIMBd9UCJU0+2KQBBMSLQ +ip5kWZ510J7/1lHtsEways+J4vtL1AkBL3qlrcyhJ9TUmc2lViQmazJtwnYtw== 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 97BA032F03 for ; Tue, 07 Jan 2025 19:37:31 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tVERb-0002wt-T1; Tue, 07 Jan 2025 13:36:47 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tVERS-0002sd-3i for emacs-orgmode@gnu.org; Tue, 07 Jan 2025 13:36:39 -0500 Received: from mout02.posteo.de ([185.67.36.66]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tVERP-0002AQ-T1 for emacs-orgmode@gnu.org; Tue, 07 Jan 2025 13:36:37 -0500 Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id F3D7C240103 for ; Tue, 7 Jan 2025 19:36:29 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1736274989; bh=aP18VIO3FkuaSti/n9hqPKoUjkd7K5kgWDrO/Gk3Xqc=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type: From; b=cCBe7nXyy9yB6quNCHXBA3kgrqrWMjJCyM3NW//q38N/u1lZEs9imkHCIlbUSawVh /M6BMdM7WH/uhdMr9gQmWAHyruE3OBX7eAyZt0JwIw2qyxMnz5gs6zuPiUo+Kc+KXL zQeW1gP/3qAvlF4IZTmJBbwYNyNS8gEEoRRHIi3FuY6Q5qNQzXcsqTKe1nbYEqdaG7 AF3x80XkTfvK5ztBgbrJ56fix9p7KXvcY+jJpqOD7okV5BmadNBGW+TMWKc/aBMB4W 0Wd873ZUt1B/xAA3sgPVb606gIRL0nLE6vv0s/+ONhFcbmEeHyjLUvNpCC0tDqnJm1 4fV63PUF6C7cg== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4YSKWd3fn9z9rxB; Tue, 7 Jan 2025 19:36:29 +0100 (CET) From: Ihor Radchenko To: Phil Estival Cc: Org Mode List Subject: Re: [PATCH] ob-sql: session In-Reply-To: <2c80ecf8-e114-45fd-8116-49ce0f975070@7d.nz> References: <646f7d12-a3d1-4a7c-83e2-5eecd7ca6817@7d.nz> <87seqrh3wl.fsf@localhost> <2c80ecf8-e114-45fd-8116-49ce0f975070@7d.nz> Date: Tue, 07 Jan 2025 18:38:48 +0000 Message-ID: <875xmq31vr.fsf@localhost> MIME-Version: 1.0 Content-Type: text/plain Received-SPF: pass client-ip=185.67.36.66; envelope-from=yantar92@posteo.net; helo=mout02.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, 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.29 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-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Scanner: mx12.migadu.com X-Migadu-Spam-Score: -5.95 X-Spam-Score: -5.95 X-Migadu-Queue-Id: 97BA032F03 X-TUID: K9MZO4RkJ2T8 Phil Estival writes: > Hello. Here we go again. Thanks! See comments inline. > Also, in the commit message of the patch for the tests, > I mention that some macros should probably be moved upward > in a file where generic functions which purposes are to help > writing the tests of babel source blocks should be declared > (ob-src-testfuncs.el for instance). > > Examples : > - result-should-contain (regexp block) : Checking that REGEXP(s) > matches the command executed when evaluating BLOCK. > - result-should-not-contain (regexp block) > - result-equals (str block) and so on. I do not mind. But please show which _other_ tests can benefit from the simplification. > +(defvar ob-sql-session--batch-end-indicator "---#" "Indicate the end of a command batch.") > +(defvar ob-sql-session-command-terminated nil) > +(defvar org-babel-sql-out-file) > +(defvar org-babel-sql-session-start-time) > + > +(sql-set-product-feature 'sqlite :prompt-regexp "sqlite> ") > +(sql-set-product-feature 'sqlite :batch-terminate > + (format ".print %s\n" ob-sql-session--batch-end-indicator)) > +(sql-set-product-feature 'sqlite :terminal-command "\\.") > + > +(sql-set-product-feature 'postgres :prompt-regexp "SQL> ") > +(sql-set-product-feature 'postgres :prompt-cont-regexp "> ") > +(sql-set-product-feature 'postgres :batch-terminate > + (format "\\echo %s\n" ob-sql-session--batch-end-indicator)) > +(sql-set-product-feature 'postgres :terminal-command "\\\\") > +(sql-set-product-feature 'postgres :environment '(("PGPASSWORD" sql-password))) > +(sql-set-product-feature > + 'postgres :sqli-options > + (list "--set=ON_ERROR_STOP=1" > + (format "--set=PROMPT1=%s" (sql-get-product-feature 'postgres :prompt-regexp )) > + (format "--set=PROMPT2=%s" (sql-get-product-feature 'postgres :prompt-cont-regexp )) > + "-P" "pager=off" > + "-P" "footer=off" > + "-A" )) All these `sql-set-product-feature' calls are overriding the defaults from sql.el. They will not only affect Org babel blocks, but all the interactive SQL sessions in Emacs. Such side effects are not acceptable. May we somehow avoid modifying pre-existing sql features? It is probably OK to add Org-specific settings after prepending them with org-. For example, :batch-terminate -> :org-batch-terminate. Although, I am not sure what is the benefit of storing these _new_ settings in the `sql-product-alist'. > +(defun ob-sql-session-buffer-live-p (buffer) > + "Return non-nil if the process associated with buffer is live. > + > +This redefines `sql-buffer-live-p' of sql.el, considering the terminal > +is valid even when `sql-interactive-mode' isn't set. BUFFER can be a buffer > +object or a buffer name. The buffer must be a live buffer, have a > +running process attached to it, and, if PRODUCT or CONNECTION are > +specified, its `sql-product' or `sql-connection' must match." > + > + (let ((buffer (get-buffer buffer))) > + (and buffer > + (buffer-live-p buffer) > + (let ((proc (get-buffer-process buffer))) > + (and proc (memq (process-status proc) '(open run))))))) May you simply use `org-babel-comint-buffer-livep' instead? > +(defun org-babel-sql-session-connect (in-engine params session) > + "Start the SQL client of IN-ENGINE if it has not. > +PARAMS provides the sql connection parameters for a new or > +existing SESSION. Clear the intermediate buffer from previous > +output, and set the process filter. Return the comint process > +buffer. > + > +The buffer naming was shortened from > +*[session] engine://user@host/database*, > +that clearly identifies the connexion from Emacs, > +to *SQL [session]* in order to retrieve a session with its > +name alone, the other parameters in the header args beeing > +no longer needed while the session stays open." > + (sql-set-product in-engine) > ... Is there any specific reason why you are seemingly re-implementing what `sql-product-interactive' does? May we re-use it instead? -- Ihor Radchenko // yantar92, Org mode maintainer, Learn more about Org mode at . Support Org development at , or support my work at