emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Patch for sql.el (quote table names in sql-list-table)


From: Matthew Carter
Subject: Patch for sql.el (quote table names in sql-list-table)
Date: Wed, 27 Jan 2016 22:37:27 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux)

Hello all,

The following patch quotes a table name when the :quotation value is set
for product features in sql.el mode, to prevent unanticipated SQL errors
in cases where the table name has something like a space (or other
reserved character) in it, as it may not be immediately apparent that
the user should have entered their quotation characters in the
sql-list-table prompt during sql-mode.

The previous behavior (no quoting) can be enabled in the user's config
file by adding something such as:

(sql-set-product-feature 'postgres :quotation nil)

diff --git a/lisp/progmodes/sql.el b/lisp/progmodes/sql.el
index 65e94ba..88e1417 100644
--- a/lisp/progmodes/sql.el
+++ b/lisp/progmodes/sql.el
@@ -430,6 +430,7 @@ file.  Since that is a plaintext file, this could be 
dangerous."
      :prompt-regexp "^mysql> "
      :prompt-length 6
      :prompt-cont-regexp "^    -> "
+     :quotation "`"
      :syntax-alist ((?# . "< b"))
      :input-filter sql-remove-tabs-filter)
 
@@ -465,6 +466,7 @@ file.  Since that is a plaintext file, this could be 
dangerous."
      :prompt-regexp "^\\w*=[#>] "
      :prompt-length 5
      :prompt-cont-regexp "^\\w*[-(][#>] "
+     :quotation "\""
      :input-filter sql-remove-tabs-filter
      :terminator ("\\(^\\s-*\\\\g$\\|;\\)" . "\\g"))
 
@@ -3768,6 +3770,9 @@ ENHANCED, displays additional details about each column."
       (user-error "No SQL interactive buffer found"))
     (unless name
       (user-error "No table name specified"))
+    (when (sql-get-product-feature sql-product :quotation)
+      (let ((quote (sql-get-product-feature sql-product :quotation)))
+        (setf name (format "%s%s%s" quote name quote))))
     (sql-execute-feature sqlbuf (format "*List %s*" name)
                          :list-table enhanced name)))
 
-- 
Matthew Carter (address@hidden)
http://ahungry.com

reply via email to

[Prev in Thread] Current Thread [Next in Thread]