GNU bug report logs - #75598
[PATCH] Quote identifiers in SQL queries in sqlite-mode

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: emacs; Severity: wishlist; Reported by: git@HIDDEN; Keywords: patch; Done: Eli Zaretskii <eliz@HIDDEN>; Maintainer for emacs is bug-gnu-emacs@HIDDEN.

Message received at 75598-done <at> debbugs.gnu.org:


Received: (at 75598-done) by debbugs.gnu.org; 25 Jan 2025 09:16:46 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sat Jan 25 04:16:46 2025
Received: from localhost ([127.0.0.1]:48478 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tbcHW-0005vi-B5
	for submit <at> debbugs.gnu.org; Sat, 25 Jan 2025 04:16:46 -0500
Received: from eggs.gnu.org ([2001:470:142:3::10]:37892)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <eliz@HIDDEN>) id 1tbcHR-0005vL-3a
 for 75598-done <at> debbugs.gnu.org; Sat, 25 Jan 2025 04:16:44 -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 <eliz@HIDDEN>)
 id 1tbcHK-0006Sw-1y; Sat, 25 Jan 2025 04:16:34 -0500
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org;
 s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date:
 mime-version; bh=GhMj7R3W27bMm1EuhHPDR3PUSNDLU9ujEn6bCAJ0z9s=; b=E3L+tRK9/Gt6
 AGJB4yimVadjmCmbwla0fgMdV0g+pcPqLSib6pFOSYfAmJmag9DylYUqTuJ5fxlGKryWr6dytR5au
 jsdjFezLdcNmwIvd+Un48k+PP+dWfttjBybNXivA0scD1vdovAX6TOQithbtYz99lE3IEhSeMHED7
 VPqHPw487cbZzlFGwNyPVOACOLT16hC4Ztv1yZn4/g55LZoqF9v11Nj+lb9fyws/XptSrPPQpckbz
 xh3+/3g4KmS2NlC6ks2J7nAmpkS8b/N9AIjNOHR7oLo5My0nGmTdPAutm8zLxO+xas11ZY6ggqu9p
 nsovl6v9O0FHNsQMiKti8g==;
Date: Sat, 25 Jan 2025 11:16:28 +0200
Message-Id: <865xm3w8wj.fsf@HIDDEN>
From: Eli Zaretskii <eliz@HIDDEN>
To: git@HIDDEN
In-Reply-To: <87bjw77whw.fsf@HIDDEN> (bug-gnu-emacs@HIDDEN)
Subject: Re: bug#75598: [PATCH] Quote identifiers in SQL queries in sqlite-mode
References: <87bjw77whw.fsf@HIDDEN>
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 75598-done
Cc: 75598-done <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

> Date: Wed, 15 Jan 2025 18:38:51 +0000
> From: git--- via "Bug reports for GNU Emacs,
>  the Swiss army knife of text editors" <bug-gnu-emacs@HIDDEN>
> 
> The sqlite-mode package does not quote identifiers (table and column
> names) in the SQL queries it performs. As a result, it e.g. cannot open
> databases which have a table called "values".
> 
> Here is a patch which fixes it for me.
> 
> Reference: https://www.sqlite.org/lang_keywords.html

Thanks, installed on the master branch, and closing the bug.




Notification sent to git@HIDDEN:
bug acknowledged by developer. Full text available.
Reply sent to Eli Zaretskii <eliz@HIDDEN>:
You have taken responsibility. Full text available.
Severity set to 'wishlist' from 'normal' Request was from Stefan Kangas <stefankangas@HIDDEN> to control <at> debbugs.gnu.org. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 16 Jan 2025 04:15:08 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Wed Jan 15 23:15:07 2025
Received: from localhost ([127.0.0.1]:59496 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tYHHc-0002gK-Cb
	for submit <at> debbugs.gnu.org; Wed, 15 Jan 2025 23:15:07 -0500
Received: from lists.gnu.org ([2001:470:142::17]:33214)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <vladimir@HIDDEN>)
 id 1tY8RU-00075q-4H
 for submit <at> debbugs.gnu.org; Wed, 15 Jan 2025 13:48:43 -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 <vladimir@HIDDEN>)
 id 1tY8RN-0004t1-Sk
 for bug-gnu-emacs@HIDDEN; Wed, 15 Jan 2025 13:48:34 -0500
Received: from f1.1azy.net ([104.244.74.192] helo=home.thecybershadow.net)
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <vladimir@HIDDEN>)
 id 1tY8RK-0003pc-Df
 for bug-gnu-emacs@HIDDEN; Wed, 15 Jan 2025 13:48:33 -0500
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed;
 d=home.thecybershadow.net; s=home; h=Sender:Content-Type:MIME-Version:
 Message-ID:Date:Subject:To:From:Reply-To:Cc:Content-Transfer-Encoding:
 Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender:
 Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Id:
 List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive;
 bh=TSGKkWkMBeNmXkcT6tT+0kza6TjiAJbxOP2QFuehHmw=; b=saIS8RlV1Qmtpya8TnQe1C9Tue
 Fh7tTfXDoXOKllba35i9d8Fw/91+AteSSSUo1qItZEal5amFenSvD22n90AsSsOgUvP7R6R1lrPpx
 ii3Yvt3gPInNtoHXa2ph6qawI9aS6wEAwDaxo0nLxeoGk6sxw3FDho1zvv6UKsoPT3Dk=;
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=cy.md;
 s=home; h=Sender:Content-Type:MIME-Version:Message-ID:Date:Subject:To:From:
 Reply-To:Cc:Content-Transfer-Encoding:Content-ID:Content-Description:
 Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:
 In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe:
 List-Post:List-Owner:List-Archive;
 bh=TSGKkWkMBeNmXkcT6tT+0kza6TjiAJbxOP2QFuehHmw=; b=r5iDduy/1QJbArDcYEw9JTBv33
 oeh8VfphxlW7PKt0r37PkHUb033vFyB4QUsQjw6pGDIbOcbpd7/4F6+8WwOZOjpdLpmojq2AYufDn
 xjguOnwRDGwuVgY5GKNc40HQPnZOTyrBsl0kFeVabJbzHVVqs5Woz5+I+QH+yA+RC3F4=;
Received: from vladimir by home.thecybershadow.net with local (Exim 4.98)
 (envelope-from <vladimir@HIDDEN>)
 id 1tY8Hz-0000000FfLW-3Sxn for bug-gnu-emacs@HIDDEN;
 Wed, 15 Jan 2025 18:38:51 +0000
From: git@HIDDEN
To: bug-gnu-emacs@HIDDEN
Subject: [PATCH] Quote identifiers in SQL queries in sqlite-mode
Date: Wed, 15 Jan 2025 18:38:51 +0000
Message-ID: <87bjw77whw.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="=-=-="
Received-SPF: pass client-ip=104.244.74.192;
 envelope-from=vladimir@HIDDEN; helo=home.thecybershadow.net
X-Spam_score_int: -17
X-Spam_score: -1.8
X-Spam_bar: -
X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,
 DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.248,
 RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001,
 SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no
X-Spam_action: no action
X-Spam-Score: 1.2 (+)
X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org",
 has NOT identified this incoming email as spam.  The original
 message has been attached to this so you can view it or label
 similar future email.  If you have any questions, see
 the administrator of that system for details.
 Content preview: Tags: patch The sqlite-mode package does not quote
 identifiers
 (table and column names) in the SQL queries it performs. As a result, it
 e.g. cannot open databases which have a table called "values". Here is a patch
 which fixes it for me. 
 Content analysis details:   (1.2 points, 10.0 required)
 pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -0.0 SPF_HELO_PASS          SPF: HELO matches SPF record
 0.2 HEADER_FROM_DIFFERENT_DOMAINS From and EnvelopeFrom 2nd level
 mail domains are different
 0.9 SPF_FAIL               SPF: sender does not match SPF record (fail)
 [SPF failed: Please see http://www.openspf.org/Why?s=mfrom;
 id=vladimir%40home.thecybershadow.net; ip=2001%3A470%3A142%3A%3A17;
 r=debbugs.gnu.org]
X-Debbugs-Envelope-To: submit
X-Mailman-Approved-At: Wed, 15 Jan 2025 23:15:03 -0500
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: 0.2 (/)

--=-=-=
Content-Type: text/plain

Tags: patch


The sqlite-mode package does not quote identifiers (table and column
names) in the SQL queries it performs. As a result, it e.g. cannot open
databases which have a table called "values".

Here is a patch which fixes it for me.

Reference: https://www.sqlite.org/lang_keywords.html

In GNU Emacs 29.1 (build 1, x86_64-pc-linux-gnu, X toolkit, cairo
version 1.18.0, Xaw3d scroll bars)
Windowing system distributor 'The X.Org Foundation', version 11.0.12101015
System Description: Arch Linux

Configured using:
 'configure
 --prefix=/nix/store/mzdvpxzkhlryxmbxwbih7bgvkzkw1ly7-emacs-29.1
 --disable-build-details --with-modules --with-x-toolkit=lucid
 --with-xft --with-cairo --with-compress-install
 --with-toolkit-scroll-bars --with-native-compilation
 --without-imagemagick --without-small-ja-dic --with-tree-sitter
 --with-xinput2 --without-xwidgets'


--=-=-=
Content-Type: text/patch
Content-Disposition: attachment;
 filename=0001-Quote-identifiers-in-SQL-queries-in-sqlite-mode.patch

From 7f85812ae501cbf4e321717e7bc7319846c76fcf Mon Sep 17 00:00:00 2001
From: Vladimir Panteleev <git@HIDDEN>
Date: Wed, 15 Jan 2025 18:33:23 +0000
Subject: [PATCH] Quote identifiers in SQL queries in sqlite-mode

* lisp/sqlite-mode.el: Quote identifiers (table and column names) in the
SQL queries. Fixes e.g. opening databases which have a table called
"values".
---
 lisp/sqlite-mode.el | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/lisp/sqlite-mode.el b/lisp/sqlite-mode.el
index 5deb8c2d7bb..a4b96b02b48 100644
--- a/lisp/sqlite-mode.el
+++ b/lisp/sqlite-mode.el
@@ -76,7 +76,7 @@ sqlite-mode-list-tables
     (erase-buffer)
     (dolist (table (sqlite-select db "select name from sqlite_master where type = 'table' and name not like 'sqlite_%' order by name"))
       (push (list (car table)
-                  (caar (sqlite-select db (format "select count(*) from %s"
+                  (caar (sqlite-select db (format "select count(*) from \"%s\""
                                                   (car table)))))
             entries))
     (sqlite-mode--tablify '("Table Name" "Number of Rows")
@@ -137,7 +137,7 @@ sqlite-mode-list-columns
 
 (defun sqlite-mode--column-names (table)
   "Return a list of the column names for TABLE."
-  (mapcar (lambda (row) (nth 1 row)) (sqlite-select sqlite--db (format "pragma table_info(%s)" table))))
+  (mapcar (lambda (row) (nth 1 row)) (sqlite-select sqlite--db (format "pragma table_info(\"%s\")" table))))
 
 (defun sqlite-mode-list-data ()
   "List the data from the table under point."
@@ -171,7 +171,7 @@ sqlite--mode--list-data
           (setq stmt
                 (sqlite-select
                  sqlite--db
-                 (format "select rowid, * from %s where rowid >= ?" table)
+                 (format "select rowid, * from \"%s\" where rowid >= ?" table)
                  (list rowid)
                  'set))
           (sqlite-mode--tablify (sqlite-columns stmt)
@@ -201,11 +201,11 @@ sqlite-mode-delete
       (user-error "Not deleting"))
     (sqlite-execute
      sqlite--db
-     (format "delete from %s where %s"
+     (format "delete from \"%s\" where %s"
              (cdr table)
              (string-join
               (mapcar (lambda (column)
-                        (format "%s = ?" (car (split-string column " "))))
+                        (format "\"%s\" = ?" (car (split-string column " "))))
                       (cons "rowid" (sqlite-mode--column-names (cdr table))))
               " and "))
      row)
-- 
2.46.0


--=-=-=--




Acknowledgement sent to git@HIDDEN:
New bug report received and forwarded. Copy sent to bug-gnu-emacs@HIDDEN. Full text available.
Report forwarded to bug-gnu-emacs@HIDDEN:
bug#75598; Package emacs. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Sat, 25 Jan 2025 09:30:02 UTC

GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997 nCipher Corporation Ltd, 1994-97 Ian Jackson.