From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Matthew Carter Newsgroups: gmane.emacs.devel Subject: Re: Patch for sql.el (quote table names in sql-list-table) Date: Thu, 28 Jan 2016 22:03:50 -0500 Organization: Ahungry (http://ahungry.com) Message-ID: <87y4b95bop.fsf@ahungry.com> References: <87egd274so.fsf@ahungry.com> <1454016205681-385599.post@n5.nabble.com> <8737th6qms.fsf@ahungry.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1454036664 30125 80.91.229.3 (29 Jan 2016 03:04:24 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 29 Jan 2016 03:04:24 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Jan 29 04:04:14 2016 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1aOzM4-0002E1-Em for ged-emacs-devel@m.gmane.org; Fri, 29 Jan 2016 04:04:12 +0100 Original-Received: from localhost ([::1]:59528 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aOzM3-0007Ka-OY for ged-emacs-devel@m.gmane.org; Thu, 28 Jan 2016 22:04:11 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:44938) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aOzLp-0007Jy-Vb for emacs-devel@gnu.org; Thu, 28 Jan 2016 22:03:59 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aOzLl-0003R3-0L for emacs-devel@gnu.org; Thu, 28 Jan 2016 22:03:57 -0500 Original-Received: from li130-200.members.linode.com ([69.164.215.200]:59600 helo=mail.ahungry.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aOzLk-0003Qz-TB for emacs-devel@gnu.org; Thu, 28 Jan 2016 22:03:52 -0500 Original-Received: from Prometheus (99-40-9-245.lightspeed.livnmi.sbcglobal.net [99.40.9.245]) by mail.ahungry.com (Postfix) with ESMTPSA id 91064118032 for ; Thu, 28 Jan 2016 22:03:50 -0500 (EST) In-Reply-To: <8737th6qms.fsf@ahungry.com> (Matthew Carter's message of "Thu, 28 Jan 2016 21:55:39 -0500") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 69.164.215.200 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:198977 Archived-At: --=-=-= Content-Type: text/plain Matthew Carter writes: > "Michael R. Mauger" 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) > > ........ > > ;; 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). --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=sql-postgres-completion-object.patch Content-Description: postgres completion object patch 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)))) --=-=-= Content-Type: text/plain -- Matthew Carter (m@ahungry.com) http://ahungry.com --=-=-=--