unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Matthew Carter <m@ahungry.com>
To: emacs-devel@gnu.org
Subject: Re: Patch for sql.el (quote table names in sql-list-table)
Date: Thu, 28 Jan 2016 22:03:50 -0500	[thread overview]
Message-ID: <87y4b95bop.fsf@ahungry.com> (raw)
In-Reply-To: <8737th6qms.fsf@ahungry.com> (Matthew Carter's message of "Thu, 28 Jan 2016 21:55:39 -0500")

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

Matthew Carter <m@ahungry.com> writes:

> "Michael R. Mauger" <michael@mauger.com> 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).


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: postgres completion object patch --]
[-- Type: text/x-diff, Size: 625 bytes --]

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

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



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

  reply	other threads:[~2016-01-29  3:03 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2016-01-30  5:31       ` Michael R. Mauger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87y4b95bop.fsf@ahungry.com \
    --to=m@ahungry.com \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).