From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms9.migadu.com with LMTPS id YFMhF/ZaUmRMFgEASxT56A (envelope-from ) for ; Wed, 03 May 2023 15:00:38 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id qDLmFvZaUmTt2QAAauVa8A (envelope-from ) for ; Wed, 03 May 2023 15:00:38 +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 095C09C74 for ; Wed, 3 May 2023 15:00:38 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1puC4x-0006eO-Q6; Wed, 03 May 2023 08:59:31 -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 1puC4w-0006e6-Og for emacs-orgmode@gnu.org; Wed, 03 May 2023 08:59:30 -0400 Received: from mr85p00im-zteg06021901.me.com ([17.58.23.194]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1puC4t-0005dS-O7 for emacs-orgmode@gnu.org; Wed, 03 May 2023 08:59:30 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=me.com; s=1a1hai; t=1683118765; bh=CogkChNtgWPnYEgY7PR0wvY0w5zoDMd4QWaWWM//9zI=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=YsCuC6AK704HnilDsvBdNdxQA348dZt6VZOrUqEf2vLl5D4ZpWzRzVldoteTtpH9B 3zEUmfzOrEXqHRyN5eWZbzmhNW4wRs1PEcg96M/8PO43Yr5/Qv4hwa9K/lVyXNL+Em b9S+rGoVXlDz1dhXxfa5GiBFR0cRHznvfHqyzBNlshvNCIOzPjD/Il3p7aFutCKapF YD0m9tFLDH+HsiJlMw9dNjgSU3D8Xk3cMhnwwgSDjk4iQUO1q31ahrAXC8tbe0RtLM CIMnYSOto9w++FqLMSq1q47IZZ74A4Zb6SCfK7nzI81HfqwrGRSnKYd97SCF/IijBy Ucqf9CAIOpTiw== Received: from localhost.localdomain (mr38p00im-dlb-asmtp-mailmevip.me.com [17.57.152.18]) by mr85p00im-zteg06021901.me.com (Postfix) with ESMTPSA id 93F2574018E; Wed, 3 May 2023 12:59:24 +0000 (UTC) From: =?UTF-8?q?Rudolf=20Adamkovi=C4=8D?= To: emacs-orgmode@gnu.org Cc: =?UTF-8?q?Rudolf=20Adamkovi=C4=8D?= Subject: [PATCH] ob-sqlite: Use a transient in-memory database by default Date: Wed, 3 May 2023 14:59:03 +0200 Message-Id: <20230503125903.95063-1-salutis@me.com> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Proofpoint-ORIG-GUID: 1q59T5A0pRkb70C8nHF_eKqdqglpwrE2 X-Proofpoint-GUID: 1q59T5A0pRkb70C8nHF_eKqdqglpwrE2 X-Proofpoint-Virus-Version: =?UTF-8?Q?vendor=3Dfsecure_engine=3D1.1.170-22c6f66c430a71ce266a39bfe25bc?= =?UTF-8?Q?2903e8d5c8f:6.0.138,18.0.572,17.11.62.513.0000000_definitions?= =?UTF-8?Q?=3D2020-02-14=5F11:2020-02-14=5F02,2020-02-14=5F11,2021-12-02?= =?UTF-8?Q?=5F01_signatures=3D0?= X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 clxscore=1015 suspectscore=0 mlxscore=0 spamscore=0 adultscore=0 mlxlogscore=999 bulkscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2305030109 Received-SPF: pass client-ip=17.58.23.194; envelope-from=salutis@me.com; helo=mr85p00im-zteg06021901.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_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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 ARC-Seal: i=1; s=key1; d=yhetil.org; t=1683118838; a=rsa-sha256; cv=none; b=AmHK7HDQi9O7aW73NLn7hi9CuGqtU0PNHyQh+1YX9wsGnQcwu0awfn3YDFY32p1XlchLIE ZH95At5UWCi9GvTV3ITQUKfu6T/x61Nrwjlp3Nc/8v7/YD7ZYNKeDM+D6ULy284K7B7ruI r3oSODYm7+jQwH6ipryFW3GXgfyfGvTCtvnKLSEdD1jrB2tFOWmT675P8/p59nioPwryps lDp5n77wIWy7Y76IB5ARBAJAteIJLFrCdHRiqTCQkayfczIH8eb4aejQ+j+Vk2nHoTgXqp Eq4fOL8C3Vv7wgo3Ed/lODlRUDn+4zj2du0+KZQBgmKUi/UPjumiPXWEs7FS5w== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=me.com header.s=1a1hai header.b=YsCuC6AK; dmarc=pass (policy=quarantine) header.from=me.com; 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" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1683118838; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=CogkChNtgWPnYEgY7PR0wvY0w5zoDMd4QWaWWM//9zI=; b=AIMir21I/ol3Nfw1ejxXWTSm6e/NuVa8EtKC4vSpPlR2YriFrczJbmin5asytgByx/8Edj u7R9EDRmKNlmIF0dv1CquaTSYnh7iavZB/VcZhW6uuTbM9xJ5Hr0ISaQgDtyft1dfTxYfS amkXCsn+gaBdsoqjHv/AZqvNO/UOtZcEsvivj9rD8RxnrLWyFm1cjacmU3fw0BRzs+6olW IHHocHGtwhThF5IdI9uJUCoWpJ28uCY5J8p3M+NcdndzqrtD8LrCEjTNTkKHbF4HLa73xe eMPI5qZQQlgBkIZJ15ocOWcBTn2qeFc1dfwPkJ5H2sCmGwfZVc4Sbeb7MUzodg== X-Migadu-Scanner: scn1.migadu.com Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=me.com header.s=1a1hai header.b=YsCuC6AK; dmarc=pass (policy=quarantine) header.from=me.com; 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" X-Migadu-Spam-Score: -6.01 X-Spam-Score: -6.01 X-Migadu-Queue-Id: 095C09C74 X-TUID: t5mHYzbVW02l * etc/ORG-NEWS (New features): Add a news entry. * lisp/ob-sqlite.el (org-babel-execute: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 | 6 ++++++ lisp/ob-sqlite.el | 3 +-- testing/lisp/test-ob-sqlite.el | 36 ++++++++++++++++++++++++++++++++-- 3 files changed, 41 insertions(+), 4 deletions(-) diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index 03894f128..42bfc2be0 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -181,6 +181,12 @@ official [[https://clojure.org/guides/deps_and_cli][Clojure CLI tools]]. The command can be customized with ~ob-clojure-cli-command~. ** New features +*** Make =ob-sqlite= use in-database by default + +SQLite source blocks with no =:db= argument now execute against a +transient in-memory database. This makes SQLite source blocks more +practical, and it matches the default behavior of the =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..60da488f7 100644 --- a/lisp/ob-sqlite.el +++ b/lisp/ob-sqlite.el @@ -66,7 +66,7 @@ "Execute a block of Sqlite code with Babel. This function is called by `org-babel-execute-src-block'." (let ((result-params (split-string (or (cdr (assq :results params)) ""))) - (db (cdr (assq :db params))) + (db (or (cdr (assq :db params)) ":memory:")) (separator (cdr (assq :separator params))) (nullvalue (cdr (assq :nullvalue params))) (headers-p (equal "yes" (cdr (assq :colnames params)))) @@ -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 diff --git a/testing/lisp/test-ob-sqlite.el b/testing/lisp/test-ob-sqlite.el index 72d75c9b7..b76a82d98 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.40.1