unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@IRO.UMontreal.CA>
To: joakim@verona.se
Cc: emacs-devel@gnu.org
Subject: Re: jdbc urls
Date: Fri, 13 Jun 2008 10:56:05 -0400	[thread overview]
Message-ID: <jwvfxrh2y6o.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <m3y75afwmo.fsf@verona.se> (joakim@verona.se's message of "Thu, 12 Jun 2008 18:25:51 +0200")

> 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




  parent reply	other threads:[~2008-06-13 14:56 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-04 11:42 jdbc urls joakim
2008-06-04 14:17 ` Chong Yidong
2008-06-04 16:03   ` joakim
2008-06-04 17:35 ` Stefan Monnier
2008-06-04 19:35   ` joakim
2008-06-05  2:11     ` Stefan Monnier
2008-06-12 16:25       ` joakim
2008-06-12 18:16         ` joakim
2008-06-13 14:56         ` Stefan Monnier [this message]
2008-06-15 22:42           ` joakim

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=jwvfxrh2y6o.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=emacs-devel@gnu.org \
    --cc=joakim@verona.se \
    /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).