From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:306:2d92::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms9.migadu.com with LMTPS id +KVxCRXozmQCSQAASxT56A (envelope-from ) for ; Sun, 06 Aug 2023 02:23:49 +0200 Received: from aspmx1.migadu.com ([2001:41d0:306:2d92::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id 0IuuCRXozmRzKwEA9RJhRA (envelope-from ) for ; Sun, 06 Aug 2023 02:23:49 +0200 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 8185331EF2 for ; Sun, 6 Aug 2023 02:23:48 +0200 (CEST) Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=me.com header.s=1a1hai header.b=sussbeuC; 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=quarantine) header.from=me.com ARC-Seal: i=1; s=key1; d=yhetil.org; t=1691281428; a=rsa-sha256; cv=none; b=QrynPVbhcqn2yGny9KihM+idU6zDK4p57pd5LMb2l1OkzVHveWymtEcjWVlLPqbVVRo0o1 dZ5yLKruKU24s5mhHdE4Zfs+tudQFL964bB3+5Os330cl0gmtpcK4OeSXiVl6uRcwdjtFo xxal91S6ElYuypXauVMEY4sfS/PDpuDNhtX630wBm36ss00ue2wmVdSkG4EdRmnh1cP9pT 2gwhPmXzuGf9A3ns6EokZbsPUBJX4RN7FbtIRIXzn/e9m8OjzhVYgPcfnAbsD4ImKVD6cX 6gXMWaqzp16RnihUm9JDDfY/O+7OGYEwKHTonGY27ob83Lohp2rDgHYrCgX7Ag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1691281428; 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=7KCgo/ThKcnf/vAPD+bzLnGcwwhXbt8rHVT6xOz636g=; b=lcM32VMch7vz8WCQH+4vGn+HDbJhkuf58a6bRGU5MiSpXOxHYn2oHR/fbStBeaecQB+a6e kRj7R7qsrwSWVAXReHcjwxgUvtYinakty+UcFaMZmnNQVt1Q6xjxS5Tj9Gt4o29AIxGKCe Mz3lvrePmkQgbJQbWbyxxuoGfspnxobhJQufJB9Ugxnnio+y+88ESFoUEnZk/uQEJ4VXhq UtjhgiBmq08h65poTVVpGjHnzDgOzNBhI+7EwOdhqgU/DMDm8vDEYEkFTSNoHibCxn475h f3eh7lp4pJZpui0/UvkmBn9RINyFVKZ5V0rxL4vdlv6pFNHB9dAJsytqUUV/TQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=me.com header.s=1a1hai header.b=sussbeuC; 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=quarantine) header.from=me.com Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qSRXp-0004ku-Fp; Sat, 05 Aug 2023 20:22:53 -0400 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 1qSRXn-0004kR-8l for emacs-orgmode@gnu.org; Sat, 05 Aug 2023 20:22:51 -0400 Received: from pv50p00im-ztdg10021201.me.com ([17.58.6.45]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qSRXk-0003bZ-Ad for emacs-orgmode@gnu.org; Sat, 05 Aug 2023 20:22:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=me.com; s=1a1hai; t=1691281362; bh=7KCgo/ThKcnf/vAPD+bzLnGcwwhXbt8rHVT6xOz636g=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; b=sussbeuCiebFy+3AdQijJuAoE8uOmxTXrC/dTYJmv+HDnbBk26QuSzdQ2EgzdP8g8 aM+ZK6MCQTPmMb2vOIeAsdGe7FZJeULlmrAcGgf8N01cYgJfHnn6Fwx+gjSd5DJVMu DfyvRNEGUNk3kDuNdGlmpMvcGWn7wtDTGp8ri/3RI69XwxDfZw8j5QjcEba9Hgd2Nx HIB5M2KD30kbRe2xYBOiFfpgOzo1BIZwbd0rp3TQuAlPPP3OSrtM713a7zE8YoW/Wq J2zQNzvCGif/Q2FP4rLfq2w0o/9oDxjYFN6C0DpbIn81j7UYDK9iho4PQfXUd+0AZ+ smJphVrgFxRsQ== Received: from Rudolfs-MacBook-Air.local (pv50p00im-dlb-asmtp-mailmevip.me.com [17.56.9.10]) by pv50p00im-ztdg10021201.me.com (Postfix) with ESMTPSA id 1E9FC680145; Sun, 6 Aug 2023 00:22:40 +0000 (UTC) From: Rudolf =?utf-8?Q?Adamkovi=C4=8D?= To: Max Nikulin Cc: emacs-orgmode@gnu.org Subject: Re: [PATCH] ob-sqlite: Use a transient in-memory database by default In-Reply-To: References: <20230503125903.95063-1-salutis@me.com> <87a5x3wum8.fsf@localhost> <87ilbis8lx.fsf@localhost> <87sf8zkz6a.fsf@localhost> Date: Sun, 06 Aug 2023 02:22:37 +0200 Message-ID: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Proofpoint-GUID: zIpusl3OTxYio1OeHimUTRyJC0TRZNwj X-Proofpoint-ORIG-GUID: zIpusl3OTxYio1OeHimUTRyJC0TRZNwj X-Proofpoint-Virus-Version: =?UTF-8?Q?vendor=3Dfsecure_engine=3D1.1.170-22c6f66c430a71ce266a39bfe25bc?= =?UTF-8?Q?2903e8d5c8f:6.0.517,18.0.883,17.0.605.474.0000000_definitions?= =?UTF-8?Q?=3D2022-06-21=5F08:2022-06-21=5F01,2022-06-21=5F08,2020-01-23?= =?UTF-8?Q?=5F02_signatures=3D0?= X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 mlxscore=0 clxscore=1015 mlxlogscore=999 bulkscore=0 suspectscore=0 malwarescore=0 adultscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2308060002 Received-SPF: pass client-ip=17.58.6.45; envelope-from=salutis@me.com; helo=pv50p00im-ztdg10021201.me.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=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-Spam-Score: -6.65 X-Migadu-Scanner: mx2.migadu.com X-Migadu-Queue-Id: 8185331EF2 X-Spam-Score: -6.65 X-TUID: V+HEcwtGwD7e --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Max Nikulin writes: > On 05/08/2023 05:57, Rudolf Adamkovi=C4=8D wrote: >> +*** Make ~ob-sqlite~ use in-database by default > > "use in-memory database" Oops! Fixed. >> +SQLite source blocks with no ~:db~ argument now execute against a >> +transient in-memory database by default. > > I am unsure, but perhaps it would be more clear to say that the default=20 > value of the header argument has changed and it is possible to omit=20 > setting :db per-block or as a header argument. It should give a hint how= =20 > to revert this change in local configuration if somebody wish it. Please see the attached Patch 0001A. > Feel free to just ignore the following. Perhaps to get *really* default=20 > behavior ob-sqlite should not check :db value and should not pass it to=20 > the command in the case of nil. This is a good idea! Please see the attached alternative Patch 0001B. > As a result the command spits a warning. It does? Rudy --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001A-ob-sqlite-Use-a-transient-in-memory-database-by-defa.patch >From 144bd75183a9185786248d9404ddeee4b93ed30f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rudolf=20Adamkovi=C4=8D?= Date: Wed, 3 May 2023 14:59:03 +0200 Subject: [PATCH] ob-sqlite: Use a transient in-memory database by default * etc/ORG-NEWS (New features): Add a news entry. * lisp/ob-sqlite.el (org-babel-default-header-args:sqlite): Default ':db' to ":memory:". * testing/lisp/test-ob-sqlite.el (ob-sqlite/in-file): Test the old behavior. * testing/lisp/test-ob-sqlite.el (ob-sqlite/in-memory): Test the new behavior. --- etc/ORG-NEWS | 8 ++++++++ lisp/ob-sqlite.el | 2 +- testing/lisp/test-ob-sqlite.el | 36 ++++++++++++++++++++++++++++++++-- 3 files changed, 43 insertions(+), 3 deletions(-) diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index 4f16eda24..569ec651b 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -489,6 +489,14 @@ Final hooks are added to the following commands: The prefix arguments are passed to ~org-insert-todo-heading~. +*** Make ~ob-sqlite~ use in-memory databases by default + +The ~:db~ header argument of ~sqlite~ source blocks now defaults to +~":memory:"~ which stands for a temporary in-memory database. As a +result, ~sqlite~ source blocks are usable out of the box, with no +header arguments, matching the behavior and practicality of the +official ~sqlite3~ shell. + *** Add support for ~logind~ idle time in ~org-user-idle-seconds~ When Emacs is built with =dbus= support and diff --git a/lisp/ob-sqlite.el b/lisp/ob-sqlite.el index 526b73ebd..75ef50913 100644 --- a/lisp/ob-sqlite.el +++ b/lisp/ob-sqlite.el @@ -39,7 +39,7 @@ (declare-function orgtbl-to-csv "org-table" (table params)) (declare-function org-table-to-lisp "org-table" (&optional txt)) -(defvar org-babel-default-header-args:sqlite '()) +(defvar org-babel-default-header-args:sqlite '((:db . ":memory:"))) (defvar org-babel-header-args:sqlite '((db . :any) diff --git a/testing/lisp/test-ob-sqlite.el b/testing/lisp/test-ob-sqlite.el index 72d75c9b7..621a11b0b 100644 --- a/testing/lisp/test-ob-sqlite.el +++ b/testing/lisp/test-ob-sqlite.el @@ -39,8 +39,40 @@ .import $tb TestTable select * from TestTable; #+end_src" - (org-babel-next-src-block) - (org-babel-execute-src-block))))) + (org-babel-next-src-block) + (org-babel-execute-src-block))))) + +(ert-deftest ob-sqlite/in-memory () + "Test in-memory temporariness." + (should + (equal 0 + (progn + (org-test-with-temp-text + "#+BEGIN_SRC sqlite +PRAGMA user_version = 1; +#+END_SRC" + (org-babel-execute-src-block)) + (org-test-with-temp-text + "#+BEGIN_SRC sqlite +PRAGMA user_version; +#+END_SRC" + (org-babel-execute-src-block)))))) + +(ert-deftest ob-sqlite/in-file () + "Test in-file permanency." + (should + (equal 1 + (let ((file (org-babel-temp-file "test" ".sqlite"))) + (org-test-with-temp-text + (format "#+BEGIN_SRC sqlite :db %s +PRAGMA user_version = 1; +#+END_SRC" file) + (org-babel-execute-src-block)) + (org-test-with-temp-text + (format "#+BEGIN_SRC sqlite :db %s +PRAGMA user_version; +#+END_SRC" file) + (org-babel-execute-src-block)))))) (provide 'test-ob-sqlite) ;;; test-ob-sqlite.el ends here -- 2.37.1 (Apple Git-137.1) --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001B-ob-sqlite-Use-a-transient-in-memory-database-by-defa.patch >From 34f28236366affb510bfdb70a3577e765d9e0abb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rudolf=20Adamkovi=C4=8D?= Date: Wed, 3 May 2023 14:59:03 +0200 Subject: [PATCH] ob-sqlite: Use a transient in-memory database by default * etc/ORG-NEWS (New features): Add a news entry. * lisp/ob-sqlite.el (org-babel-execute:sqlite): Default ':db' to ":memory:" instead of throwing an error. * testing/lisp/test-ob-sqlite.el (ob-sqlite/in-file): Test the old behavior. * testing/lisp/test-ob-sqlite.el (ob-sqlite/in-memory): Test the new behavior. --- etc/ORG-NEWS | 8 ++++++++ lisp/ob-sqlite.el | 3 +-- testing/lisp/test-ob-sqlite.el | 36 ++++++++++++++++++++++++++++++++-- 3 files changed, 43 insertions(+), 4 deletions(-) diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index 4f16eda24..3426a5bc0 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -489,6 +489,14 @@ Final hooks are added to the following commands: The prefix arguments are passed to ~org-insert-todo-heading~. +*** Make ~ob-sqlite~ use in-memory databases by default + +~sqlite~ source blocks with no ~:db~ header argument now make SQLite +use a temporary in-memory database instead of throwing an error, +matching the behavior of the official ~sqlite3~ shell. As a result, +~sqlite~ source blocks are now usable out of the box, that is with no +header arguments. + *** Add support for ~logind~ idle time in ~org-user-idle-seconds~ When Emacs is built with =dbus= support and diff --git a/lisp/ob-sqlite.el b/lisp/ob-sqlite.el index 526b73ebd..7510e5158 100644 --- a/lisp/ob-sqlite.el +++ b/lisp/ob-sqlite.el @@ -74,7 +74,6 @@ This function is called by `org-babel-execute-src-block'." (lambda (arg) (car (assq arg params))) (list :header :echo :bail :column :csv :html :line :list))))) - (unless db (error "ob-sqlite: can't evaluate without a database")) (with-temp-buffer (insert (org-babel-eval @@ -97,7 +96,7 @@ This function is called by `org-babel-execute-src-block'." (member :html others) separator) "" "-csv")) - (cons "db " db))) + (cons "db" (or db "")))) ;; body of the code block (org-babel-expand-body:sqlite body params))) (org-babel-result-cond result-params diff --git a/testing/lisp/test-ob-sqlite.el b/testing/lisp/test-ob-sqlite.el index 72d75c9b7..621a11b0b 100644 --- a/testing/lisp/test-ob-sqlite.el +++ b/testing/lisp/test-ob-sqlite.el @@ -39,8 +39,40 @@ .import $tb TestTable select * from TestTable; #+end_src" - (org-babel-next-src-block) - (org-babel-execute-src-block))))) + (org-babel-next-src-block) + (org-babel-execute-src-block))))) + +(ert-deftest ob-sqlite/in-memory () + "Test in-memory temporariness." + (should + (equal 0 + (progn + (org-test-with-temp-text + "#+BEGIN_SRC sqlite +PRAGMA user_version = 1; +#+END_SRC" + (org-babel-execute-src-block)) + (org-test-with-temp-text + "#+BEGIN_SRC sqlite +PRAGMA user_version; +#+END_SRC" + (org-babel-execute-src-block)))))) + +(ert-deftest ob-sqlite/in-file () + "Test in-file permanency." + (should + (equal 1 + (let ((file (org-babel-temp-file "test" ".sqlite"))) + (org-test-with-temp-text + (format "#+BEGIN_SRC sqlite :db %s +PRAGMA user_version = 1; +#+END_SRC" file) + (org-babel-execute-src-block)) + (org-test-with-temp-text + (format "#+BEGIN_SRC sqlite :db %s +PRAGMA user_version; +#+END_SRC" file) + (org-babel-execute-src-block)))))) (provide 'test-ob-sqlite) ;;; test-ob-sqlite.el ends here -- 2.37.1 (Apple Git-137.1) --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable --=20 "'Obvious' is all too often a synonym for 'wrong'." -- Jeff Erickson, Algorithms, 2019 Rudolf Adamkovi=C4=8D [he/him] Studenohorsk=C3=A1 25 84103 Bratislava Slovakia --=-=-=--