]> git.eshelyaron.com Git - emacs.git/commitdiff
Quote identifiers in SQL queries in 'sqlite-mode'
authorVladimir Panteleev <git@cy.md>
Wed, 15 Jan 2025 18:33:23 +0000 (18:33 +0000)
committerEshel Yaron <me@eshelyaron.com>
Sat, 25 Jan 2025 17:46:41 +0000 (18:46 +0100)
* lisp/sqlite-mode.el: (sqlite-mode-list-tables)
(sqlite-mode-list-columns, sqlite--mode--list-data)
(sqlite-mode-delete): Quote identifiers (table and column
names) in the SQL queries.  Fixes, e.g., opening databases
which have a table called "values".  (Bug#75598)

(cherry picked from commit 5e0fc49f3b14928f08eb314b15f70ccbb2ce7229)

lisp/sqlite-mode.el

index 5deb8c2d7bb610708fadd2a77ae6c1dd51b94c7b..a4b96b02b488a1c00ee1de2c6f2c20a8672cd487 100644 (file)
@@ -76,7 +76,7 @@
     (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")
 
 (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."
           (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)
       (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)