summaryrefslogtreecommitdiff
path: root/lisp/sqlite-mode.el
diff options
context:
space:
mode:
authorVladimir Panteleev <git@cy.md>2025-01-15 18:33:23 +0000
committerEli Zaretskii <eliz@gnu.org>2025-01-25 11:14:01 +0200
commit5e0fc49f3b14928f08eb314b15f70ccbb2ce7229 (patch)
tree6ba901a188cdb4debd96f294ec7ba569114277df /lisp/sqlite-mode.el
parent13fdcd730ff63bf79caace9a6e46aff5f944b1b7 (diff)
Quote identifiers in SQL queries in 'sqlite-mode'
* 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)
Diffstat (limited to 'lisp/sqlite-mode.el')
-rw-r--r--lisp/sqlite-mode.el10
1 files 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 @@
(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 @@
(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 @@
(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 @@
(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)