[Top][All Lists]

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

Re: jdbc urls

From: Stefan Monnier
Subject: Re: jdbc urls
Date: Fri, 13 Jun 2008 10:56:05 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux)

> 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 ;-)


reply via email to

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