unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Patch for sql.el (quote table names in sql-list-table)
@ 2016-01-28  3:37 Matthew Carter
  2016-01-28 21:23 ` Michael R. Mauger
  0 siblings, 1 reply; 5+ messages in thread
From: Matthew Carter @ 2016-01-28  3:37 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 556 bytes --]

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)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Quote the table name --]
[-- Type: text/x-diff, Size: 1237 bytes --]

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)))
 \f

[-- Attachment #3: Type: text/plain, Size: 55 bytes --]


-- 
Matthew Carter (m@ahungry.com)
http://ahungry.com

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2016-01-30  5:31 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-01-28  3:37 Patch for sql.el (quote table names in sql-list-table) Matthew Carter
2016-01-28 21:23 ` Michael R. Mauger
2016-01-29  2:55   ` Matthew Carter
2016-01-29  3:03     ` Matthew Carter
2016-01-30  5:31       ` Michael R. Mauger

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).