]> git.eshelyaron.com Git - emacs.git/commitdiff
(sqlite-mode--column-names): Suppport nested parens
authorYoav Marco <yoavm448@gmail.com>
Wed, 11 May 2022 12:05:37 +0000 (14:05 +0200)
committerLars Ingebrigtsen <larsi@gnus.org>
Wed, 11 May 2022 12:05:37 +0000 (14:05 +0200)
* lisp/sqlite-mode.el (sqlite-mode--column-names): Make parsing
more resilient (bug#55363).

Copyright-paperwork-exempt: yes

lisp/sqlite-mode.el

index ba1b81ef7e25a971638ad4466a77aa3bc88392b1..66e2e487d9c13c56049edb2aaccd8575abcca737 100644 (file)
             (insert (format "  %s\n" column))))))))
 
 (defun sqlite-mode--column-names (table)
+  "Return a list of the column names for TABLE."
   (let ((sql
          (caar
           (sqlite-select
            sqlite--db
            "select sql from sqlite_master where tbl_name = ? AND type = 'table'"
            (list table)))))
-    (mapcar
-     #'string-trim
-     (split-string (replace-regexp-in-string "^.*(\\|)$" "" sql) ","))))
+    (with-temp-buffer
+      (insert sql)
+      (mapcar #'string-trim
+              (split-string
+               ;; Extract the args to CREATE TABLE.  Point is
+               ;; currently at its end.
+               (buffer-substring
+                (1- (point))                          ; right before )
+                (1+ (progn (backward-sexp) (point)))) ; right after (
+               ",")))))
 
 (defun sqlite-mode-list-data ()
   "List the data from the table under point."