diff options
| author | Vladimir Panteleev | 2025-01-15 18:33:23 +0000 |
|---|---|---|
| committer | Eli Zaretskii | 2025-01-25 11:14:01 +0200 |
| commit | 5e0fc49f3b14928f08eb314b15f70ccbb2ce7229 (patch) | |
| tree | 6ba901a188cdb4debd96f294ec7ba569114277df | |
| parent | 13fdcd730ff63bf79caace9a6e46aff5f944b1b7 (diff) | |
| download | emacs-5e0fc49f3b14928f08eb314b15f70ccbb2ce7229.tar.gz emacs-5e0fc49f3b14928f08eb314b15f70ccbb2ce7229.zip | |
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)
| -rw-r--r-- | lisp/sqlite-mode.el | 10 |
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 @@ | |||
| 76 | (erase-buffer) | 76 | (erase-buffer) |
| 77 | (dolist (table (sqlite-select db "select name from sqlite_master where type = 'table' and name not like 'sqlite_%' order by name")) | 77 | (dolist (table (sqlite-select db "select name from sqlite_master where type = 'table' and name not like 'sqlite_%' order by name")) |
| 78 | (push (list (car table) | 78 | (push (list (car table) |
| 79 | (caar (sqlite-select db (format "select count(*) from %s" | 79 | (caar (sqlite-select db (format "select count(*) from \"%s\"" |
| 80 | (car table))))) | 80 | (car table))))) |
| 81 | entries)) | 81 | entries)) |
| 82 | (sqlite-mode--tablify '("Table Name" "Number of Rows") | 82 | (sqlite-mode--tablify '("Table Name" "Number of Rows") |
| @@ -137,7 +137,7 @@ | |||
| 137 | 137 | ||
| 138 | (defun sqlite-mode--column-names (table) | 138 | (defun sqlite-mode--column-names (table) |
| 139 | "Return a list of the column names for TABLE." | 139 | "Return a list of the column names for TABLE." |
| 140 | (mapcar (lambda (row) (nth 1 row)) (sqlite-select sqlite--db (format "pragma table_info(%s)" table)))) | 140 | (mapcar (lambda (row) (nth 1 row)) (sqlite-select sqlite--db (format "pragma table_info(\"%s\")" table)))) |
| 141 | 141 | ||
| 142 | (defun sqlite-mode-list-data () | 142 | (defun sqlite-mode-list-data () |
| 143 | "List the data from the table under point." | 143 | "List the data from the table under point." |
| @@ -171,7 +171,7 @@ | |||
| 171 | (setq stmt | 171 | (setq stmt |
| 172 | (sqlite-select | 172 | (sqlite-select |
| 173 | sqlite--db | 173 | sqlite--db |
| 174 | (format "select rowid, * from %s where rowid >= ?" table) | 174 | (format "select rowid, * from \"%s\" where rowid >= ?" table) |
| 175 | (list rowid) | 175 | (list rowid) |
| 176 | 'set)) | 176 | 'set)) |
| 177 | (sqlite-mode--tablify (sqlite-columns stmt) | 177 | (sqlite-mode--tablify (sqlite-columns stmt) |
| @@ -201,11 +201,11 @@ | |||
| 201 | (user-error "Not deleting")) | 201 | (user-error "Not deleting")) |
| 202 | (sqlite-execute | 202 | (sqlite-execute |
| 203 | sqlite--db | 203 | sqlite--db |
| 204 | (format "delete from %s where %s" | 204 | (format "delete from \"%s\" where %s" |
| 205 | (cdr table) | 205 | (cdr table) |
| 206 | (string-join | 206 | (string-join |
| 207 | (mapcar (lambda (column) | 207 | (mapcar (lambda (column) |
| 208 | (format "%s = ?" (car (split-string column " ")))) | 208 | (format "\"%s\" = ?" (car (split-string column " ")))) |
| 209 | (cons "rowid" (sqlite-mode--column-names (cdr table)))) | 209 | (cons "rowid" (sqlite-mode--column-names (cdr table)))) |
| 210 | " and ")) | 210 | " and ")) |
| 211 | row) | 211 | row) |