From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1.migadu.com ([2001:41d0:403:4876::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms8.migadu.com with LMTPS id YBpuK8rR2GVoaAEA62LTzQ:P1 (envelope-from ) for ; Fri, 23 Feb 2024 18:11:38 +0100 Received: from aspmx1.migadu.com ([2001:41d0:403:4876::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1.migadu.com with LMTPS id YBpuK8rR2GVoaAEA62LTzQ (envelope-from ) for ; Fri, 23 Feb 2024 18:11:38 +0100 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gnu.org header.s=fencepost-gnu-org header.b=b29fuO+d; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org"; dmarc=pass (policy=none) header.from=gnu.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1708708298; 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: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=iANDY7egFyBAPh+lxHjQjHxC04dRZEtNAaR9xGg1JP4=; b=k/5TgGTDlOb9SK5QenInIcsyf7hj0UYhFe4wcO9TJWtua2R0R0K36IAmlZJuckSMgivW01 kB1dnaqVbVsb5aqkGvLK4VqxSJnB23VOH2pCi7sTw9z/alpLW2VQ5htqGcyHodVUW4l4SU CHy/giIpkRhoRlM0Jdl8hR6rrS2WL4IwK7T/KTJD1V0hkI5K0kYeSBbl1Nxj5MDJqRFED2 ZF470jMOON3o9K0EI6KLnHLDLA/UEWqRGMqyPHpOEcItHU1lBYQjKxvpaZj81g0W4frWLa 4YFtc47dcCCW5tHoU7KC2XzdtHBb25gPheAFAM++WZkosiKnPTFAR4AUXa131A== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gnu.org header.s=fencepost-gnu-org header.b=b29fuO+d; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org"; dmarc=pass (policy=none) header.from=gnu.org ARC-Seal: i=1; s=key1; d=yhetil.org; t=1708708298; a=rsa-sha256; cv=none; b=f9Y1yTjBoecVOve/B0GaX8JldhnqrqiFdT4GK+fFWJMIJp6qx2A5agps8/ycyyg9ScXGrt lOfGeBMnKDkSTDvtEii1ZvPtELdPnBwyK+DPgOOkJLW3lHTjNISbjKxMhqVRnuxCWqrlmA R+DD0ALmaZIaah8AyvnPqDKFPnRDx7GCXf2uva/EfzsDArimrR7eYSZ593qf1Jun3iSeHQ m1B+zk816Wsxw7of2/rLA18rrdUjEGXLmDwvybEhs/UkPsGsHCriCbOpnr4BOG9bBKe8Pf yjPvRt6XCuBBL91a4klx25xVDd1ol/0tKklzR0uZ1fjqyorUIoJt9sMleNfJ1Q== 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 9BC8375985 for ; Fri, 23 Feb 2024 18:11:38 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rdZ4g-0007xx-PT; Fri, 23 Feb 2024 12:11:04 -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 1rdYpn-0007fy-TP for guix-patches@gnu.org; Fri, 23 Feb 2024 11:55:40 -0500 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rdYpn-0003uA-HQ for guix-patches@gnu.org; Fri, 23 Feb 2024 11:55:39 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rdYqA-0005SQ-SP for guix-patches@gnu.org; Fri, 23 Feb 2024 11:56:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#69292] [PATCH 3/6] store: database: Inline SQL to where it's used. Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Fri, 23 Feb 2024 16:56:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 69292 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: Christopher Baines Cc: Josselin Poiret , Simon Tournier , Mathieu Othacehe , Tobias Geerinckx-Rice , Ricardo Wurmus , 69292@debbugs.gnu.org, Christopher Baines Received: via spool by 69292-submit@debbugs.gnu.org id=B69292.170870731920818 (code B ref 69292); Fri, 23 Feb 2024 16:56:02 +0000 Received: (at 69292) by debbugs.gnu.org; 23 Feb 2024 16:55:19 +0000 Received: from localhost ([127.0.0.1]:53687 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rdYpR-0005Pd-QH for submit@debbugs.gnu.org; Fri, 23 Feb 2024 11:55:18 -0500 Received: from eggs.gnu.org ([209.51.188.92]:34142) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rdYbk-0004c2-6s for 69292@debbugs.gnu.org; Fri, 23 Feb 2024 11:41:09 -0500 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rdYbF-0000tx-8y; Fri, 23 Feb 2024 11:40:37 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:Date:References:In-Reply-To:Subject:To: From; bh=iANDY7egFyBAPh+lxHjQjHxC04dRZEtNAaR9xGg1JP4=; b=b29fuO+dR31phLqdwZ1d VGqP0EDHhcVtlvjVttXgQTkjY2RAWmyYX+2TCbnzQBM7dlF4Th2aXpU4Hbzl+25kV4jMkJoqYLmuX NlZscWwefOPXlsa6u54lT6riCn3BggM/pOb4laM8kqGstKtDIKhiXaPLbghUKKMJlf9NjKSRt7ThI nEz8mcy14EnMvExQiVhHBBKudtl2wc992GzxTpZgdTFTqfrcoNe7EjCi5jLk8Viz+S8qnPd2eWJG9 +zQajdeYO6fRw6tCsLW4DgNpzD5/+Ie6YJA59ZAcmFb6/Uwa+KxVq72ANVp6Z8KNLNOFY8UhmJzBW I5wMFcq/k9nqDQ==; From: Ludovic =?UTF-8?Q?Court=C3=A8s?= In-Reply-To: <5abcabc4cb65ea63db7c4f046700116e4882b287.1708457946.git.mail@cbaines.net> (Christopher Baines's message of "Tue, 20 Feb 2024 19:39:03 +0000") References: <4b6a268daab5e0b307dff2229d551a47c9fe1ebc.1708457946.git.mail@cbaines.net> <5abcabc4cb65ea63db7c4f046700116e4882b287.1708457946.git.mail@cbaines.net> Date: Fri, 23 Feb 2024 17:40:29 +0100 Message-ID: <874jdzf81u.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: guix-patches-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Scanner: mx10.migadu.com X-Migadu-Spam-Score: -1.14 X-Spam-Score: -1.14 X-Migadu-Queue-Id: 9BC8375985 X-TUID: PsMHb9aTHAlI Christopher Baines skribis: > This makes the code easier to read, as you don't have to keep jumping bet= ween > the two places. > > * guix/store/database.scm (path-id-sql, update-sql, insert-sql, > add-reference-sql): Remove variables. > (path-id, update-or-insert, add-references): Include SQL. > > Change-Id: I53b4ab973be8d0cd10a0f35ba25972f1c9680353 LGTM. > (let ((id (path-id db path))) > (if id > - (let ((stmt (sqlite-prepare db update-sql #:cache? #t))) > + (let ((stmt (sqlite-prepare > + db > + " > +UPDATE ValidPaths > +SET hash =3D :hash, > + registrationTime =3D :time, > + deriver =3D :deriver, > + narSize =3D :size > +WHERE id =3D :id" > + #:cache? #t))) I think we can make it a bit more dense (3 or 4 lines in total for the statement). :-) In the future, we should probably add a macro to sqlite3 like that one from Cuirass: --8<---------------cut here---------------start------------->8--- (define-syntax-rule (exec-query/bind db query args ...) "Execute the specific QUERY with the given ARGS. Uses of 'exec-query/bin= d' typically look like this: (exec-query/bind db \"SELECT * FROM Foo WHERE x =3D \" x \"AND Y=3D\" y \= ";\") References to variables 'x' and 'y' here are replaced by $1 and $2 in the SQL query. This ensures that (1) SQL injection is impossible, and (2) the number of parameters matches the number of arguments to bind." (%exec-query/bind db () "" query args ...)) --8<---------------cut here---------------end--------------->8--- That makes things slightly more readable IMO since you don=E2=80=99t end up= with two separate calls, one to prepare the statement and the other one to bind its arguments. Ludo=E2=80=99.