[Top][All Lists]

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

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

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

Matthew Carter <address@hidden> writes:

> "Michael R. Mauger" <address@hidden> writes:
>> I'd discourage this change. The List Tables prompt does not prevent use of
>> identifier enclosing characters and by not using them you get the default
>> case conversion behavior. There are also cases with MS SQL Server where the
>> enclosing character is not a single character but rather a [ and ] pair.
>> I'd also be concerned when I ask to list the table in another schema since
>> we'd now be enclosing the schema and table name within the quotes which is
>> clearly not what we want.
>> --
>> View this message in context: 
>> http://emacs.1067599.n5.nabble.com/Patch-for-sql-el-quote-table-names-in-sql-list-table-tp385543p385599.html
>> Sent from the Emacs - Dev mailing list archive at Nabble.com.
> The original problem/issue I had with this arised from the following
> function in sql.el (the one that generates the postgres completion
> candidate list):
> (defun sql-postgres-completion-object (sqlbuf schema)
> ....<snip>....
>       ;; Return the list of table names (public schema name can be omitted)
>       (mapcar #'(lambda (tbl)
>                   (if (string= (car tbl) "public")
>                       (cadr tbl)
>                     (format "%s.%s" (car tbl) (cadr tbl))))
>               cl))))
> As you can see, in a schema that includes tables with spaces in their
> names, those become completion objects ("Foo Bar" for instance,
> sans quotes of course).
> When something that then goes to make use of the completion list tries
> to pass along "Foo Bar" (sans quotes) to the function that I
> patched, it causes an issue.
> With a little modification, my original patch could account for
> differing open/close quotations as you referenced (and the patch itself
> does nothing if the quotation feature is not set).
> Do you think a better fix would be to quote the postgres completion list
> when necessary?  (if a space in one of the table names is found)?
> Because as it is, it doesn't work well with some completion modes like
> helm (which just display the completion list candidates verbatim, and
> expect the user to press RET on one of them to select it).

Attached is an alternate patch which at least fixes the postgres
completion list to quote both the schema and table names (I can't think
of a situation in which it would hurt for this to be quoted).

diff --git a/lisp/progmodes/sql.el b/lisp/progmodes/sql.el
index 65e94ba..fd59f46 100644
--- a/lisp/progmodes/sql.el
+++ b/lisp/progmodes/sql.el
@@ -4948,8 +4948,8 @@ Try to set `comint-output-filter-functions' like this:
       ;; Return the list of table names (public schema name can be omitted)
       (mapcar #'(lambda (tbl)
                   (if (string= (car tbl) "public")
-                      (cadr tbl)
-                    (format "%s.%s" (car tbl) (cadr tbl))))
+                      (format "\"%s\"" (cadr tbl))
+                    (format "\"%s\".\"%s\"" (car tbl) (cadr tbl))))

Matthew Carter (address@hidden)

reply via email to

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