From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: jdbc urls Date: Fri, 13 Jun 2008 10:56:05 -0400 Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1213369054 8503 80.91.229.12 (13 Jun 2008 14:57:34 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 13 Jun 2008 14:57:34 +0000 (UTC) Cc: emacs-devel@gnu.org To: joakim@verona.se Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Jun 13 16:58:17 2008 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1K7Aj7-0003Yf-L1 for ged-emacs-devel@m.gmane.org; Fri, 13 Jun 2008 16:58:05 +0200 Original-Received: from localhost ([127.0.0.1]:43952 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1K7AiJ-0003iO-EN for ged-emacs-devel@m.gmane.org; Fri, 13 Jun 2008 10:57:15 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1K7AiE-0003fz-E7 for emacs-devel@gnu.org; Fri, 13 Jun 2008 10:57:10 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1K7AiC-0003dp-Am for emacs-devel@gnu.org; Fri, 13 Jun 2008 10:57:08 -0400 Original-Received: from [199.232.76.173] (port=51104 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1K7AiC-0003da-3a for emacs-devel@gnu.org; Fri, 13 Jun 2008 10:57:08 -0400 Original-Received: from chene.dit.umontreal.ca ([132.204.246.20]:35867) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1K7AiB-0003Ys-KD for emacs-devel@gnu.org; Fri, 13 Jun 2008 10:57:07 -0400 Original-Received: from ceviche.home (vpn-132-204-232-131.acd.umontreal.ca [132.204.232.131]) by chene.dit.umontreal.ca (8.14.1/8.14.1) with ESMTP id m5DEv6de021266 for ; Fri, 13 Jun 2008 10:57:06 -0400 Original-Received: by ceviche.home (Postfix, from userid 20848) id EC3E2B4087; Fri, 13 Jun 2008 10:56:05 -0400 (EDT) In-Reply-To: (joakim@verona.se's message of "Thu, 12 Jun 2008 18:25:51 +0200") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux) X-NAI-Spam-Score: 0 X-NAI-Spam-Rules: 2 Rules triggered HAS_X_HELO=0, RV3037=0 X-detected-kernel: by monty-python.gnu.org: Linux 2.6 (newer, 3) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:99104 Archived-At: > I meant to as if the file looks ok, See anal retentive comments below. > and if thats all there is to it when adding support for a new url type? I wouldn't know. It should be explained in the URL doc somewhere. I'd be surprised if that doc was enough for you to code this up, so anything you've learned about URL while writing this code would be welcome in the form of a patch to the doc (even in rough form, I'd be happy to improve it afterwards). > Also, is there some library that uses url-lib to provide ffap like > functionality? What do you mean by ffap-like functionality? > ;; url-jdbc enables parsing of some jdbc urls, and connecting with > ;; emacs sql mode to the database described by the url. Try C-u checkdoc-current-buffer RET. It'll help you fix things like "emacs" -> "Emacs". > ;;Jdbc urls are funny in the sense that they are rfc > ;;compliant, but the "hier-part" doesnt necessarily come immediately > ;;after the "scheme". So, jdbc urls only have scheme:path, where path > ;;sometimes looks like a hier-part. Add a space after the ";;" and two spaces after a "." that ends a sentence. I don't know what's a "hier-part", so I don't understand much of the above. > ;; Its up to the driver to parse the url string after the "driver" part ^^ ' > ;; of the url. Since the postgres driver and mysql driver both look > ;; like a url after the scheme part, we parse the path part like a url > ;; for these. Several other jdbc drivers work like this. > ;;examples Capitalize, and add a ":". > ;(url-parse-query-string) Reindent will move this to column 32: better use ";;". > (defun url-jdbc (url-orig) This needs a docstring. > (let* ( > (url (url-generic-parse-url (url-filename url-orig)));see commentary to understand this > (driver (url-type url)) > (sql-server (url-host url)) > (sql-port (url-port url)) > (sql-password (url-password url)) > (sql-user (url-user url)) > (rest (url-filename url)) > (args nil) > (headers-start nil) > (sql-database (url-file-nondirectory rest)) > ) Avoid opening parens at end of line, as well as closing parens on their own lines. Lisp is not C. > ;;get the url query attributes Please capitalize your comments and terminate them with ".". > ; (message "jdbc driver:%s host:%s db:%s usr:%s pwd:%s args:%s rest:%s" driver sql-server sql-database sql-user sql-password args rest) Same comment as above: reindent will mess this up. Use ";;" and use TAB to make sure it's indented right. > (defun url-jdbc-connect (driver sql-server sql-port sql-database sql-user sql-password args) > ;many jdbc drivers define user/pwd in the option string, contrary to url std. > ;postgres and mysql in particular > (if sql-user nil (setq sql-user (symbol-name (cadr(assq 'user x))))) > (if sql-password nil (setq sql-password (symbol-name (cadr(assq 'password x))))) You can use (unless sql-user (setq ...)) > (cond > ((string= "postgresql" driver) > (sql-postgres)) > ((string= "mysql" driver) > (sql-mysql)) > (t (message "no driver matched")) Shouldn't this be an error rather than a message? > (provide 'url-jdbc) > (provide 'url-jdbc) I believe `provide' is fairly reliable, and even if it fails, I doubt that calling it a second time will fix the first failure ;-) Stefan