all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* jdbc urls
@ 2008-06-04 11:42 joakim
  2008-06-04 14:17 ` Chong Yidong
  2008-06-04 17:35 ` Stefan Monnier
  0 siblings, 2 replies; 10+ messages in thread
From: joakim @ 2008-06-04 11:42 UTC (permalink / raw)
  To: emacs-devel

I have some rusty code lying about for jdbc urls, for
emacs-planner, but that can be changed. I would like to polish the code
and submit it for inclusion, but first some questions:

- Is there something like this already that I didnt notice?
- Should this code go into ffap?

What the code currently does is to open the interactive sql mode for
jdbc urls. Only Emacs facilities are used, no Java.

-- 
Joakim Verona




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: jdbc urls
  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
  1 sibling, 1 reply; 10+ messages in thread
From: Chong Yidong @ 2008-06-04 14:17 UTC (permalink / raw)
  To: joakim; +Cc: emacs-devel

joakim@verona.se writes:

> I have some rusty code lying about for jdbc urls, for
> emacs-planner, but that can be changed. I would like to polish the code
> and submit it for inclusion, but first some questions:
>
> - Is there something like this already that I didnt notice?

Not as far as I know.

> - Should this code go into ffap?
>
> What the code currently does is to open the interactive sql mode for
> jdbc urls. Only Emacs facilities are used, no Java.

It depends on how large the code is.  If you posted a patch, we would be
able to get a better idea.




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: jdbc urls
  2008-06-04 14:17 ` Chong Yidong
@ 2008-06-04 16:03   ` joakim
  0 siblings, 0 replies; 10+ messages in thread
From: joakim @ 2008-06-04 16:03 UTC (permalink / raw)
  To: Chong Yidong; +Cc: emacs-devel

Chong Yidong <cyd@stupidchicken.com> writes:
>
> It depends on how large the code is.  If you posted a patch, we would be
> able to get a better idea.

This is the code I use for "planner".
My thought was that it could be better implemented in ffap.

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; jdbc urls
(defun planner-browse-url-jdbc (url)
  "Browse JDBC URLs."
  ;; code for browsing JDBC URLs
  ;; url to test  with:
  (string-match "jdbc:\\([^:/]*\\)://\\([^/]*\\)/\\([^?]*\\).user=\\([^&]*\\)&password=\\(.*\\)" url)
  (let
      ((driver (match-string 1 url))
       (sql-server   (match-string 2 url))
       (sql-database   (match-string 3 url))
       (sql-user   (match-string 4 url))
       (sql-password   (match-string 5 url))
       )
      (message "jdbc url:%s driver:%s host:%s db:%s usr:%s pwd:%s" url driver sql-server sql-database sql-user sql-password)
      (sql-postgres)
      (sql-rename-buffer) ;renames the buffer to something useful
    )
  )


;jdbc:\\([^:/]*\\)://\\([^/]*\\)/\\([^?]*\\).user=\\([^&]*\\)&password=\\(.*\\)
(defun planner-resolve-url-jdbc (url)
  "Resolve JDBC URLs."
  ;; Turn a JDBC URL into an http:// URL, if applicable
  ;; Otherwise omit this and use 'identify below
nil)

(planner-add-protocol "jdbc:" 'planner-browse-url-jdbc
                                'planner-resolve-url-jdbc)

;; So if you activate a url like:
;; jdbc:postgresql://localhost/pgdatabase?user=demo&password=demo

;; it will open that server in sql mode.

;; TODO:
;; - driver is just ignored, should for to the correct postgres/mssql
;; whatever driver function. currently it just does postgres
;; - sql mode prompts for arguments, with the data suplied in the jdbc
;; url as defaults, I would rather not have it prompt.
;; - try to remember if there is a buffer for this url already and optionaly go there instead

--
Joakim Verona




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: jdbc urls
  2008-06-04 11:42 jdbc urls joakim
  2008-06-04 14:17 ` Chong Yidong
@ 2008-06-04 17:35 ` Stefan Monnier
  2008-06-04 19:35   ` joakim
  1 sibling, 1 reply; 10+ messages in thread
From: Stefan Monnier @ 2008-06-04 17:35 UTC (permalink / raw)
  To: joakim; +Cc: emacs-devel

> I have some rusty code lying about for jdbc urls, for
> emacs-planner, but that can be changed. I would like to polish the code
> and submit it for inclusion, but first some questions:

> - Is there something like this already that I didnt notice?
> - Should this code go into ffap?

Shouldn't it logically go into lisp/url/url-jdbc.el instead?


        Stefan




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: jdbc urls
  2008-06-04 17:35 ` Stefan Monnier
@ 2008-06-04 19:35   ` joakim
  2008-06-05  2:11     ` Stefan Monnier
  0 siblings, 1 reply; 10+ messages in thread
From: joakim @ 2008-06-04 19:35 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> I have some rusty code lying about for jdbc urls, for
>> emacs-planner, but that can be changed. I would like to polish the code
>> and submit it for inclusion, but first some questions:
>
>> - Is there something like this already that I didnt notice?
>> - Should this code go into ffap?
>
> Shouldn't it logically go into lisp/url/url-jdbc.el instead?
>

That does indeed seem more logical.

I am new to this area of Emacs. I have always used ffap.
It appears ffap has it own functions that does similar things as
url-lib, for instance ffap-url-at-point, and url-get-url-at-point.

The url lib documentation doesnt seem complete.

I suppose my question is: If I write url-jdbc, how can I make it be
accepted by ffap? Or is there some other facility that superceedes ffap?



>
>         Stefan
-- 
Joakim Verona




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: jdbc urls
  2008-06-04 19:35   ` joakim
@ 2008-06-05  2:11     ` Stefan Monnier
  2008-06-12 16:25       ` joakim
  0 siblings, 1 reply; 10+ messages in thread
From: Stefan Monnier @ 2008-06-05  2:11 UTC (permalink / raw)
  To: joakim; +Cc: emacs-devel

>>> I have some rusty code lying about for jdbc urls, for
>>> emacs-planner, but that can be changed. I would like to polish the code
>>> and submit it for inclusion, but first some questions:
>> 
>>> - Is there something like this already that I didnt notice?
>>> - Should this code go into ffap?
>> 
>> Shouldn't it logically go into lisp/url/url-jdbc.el instead?

> That does indeed seem more logical.

> I am new to this area of Emacs. I have always used ffap.
> It appears ffap has it own functions that does similar things as
> url-lib, for instance ffap-url-at-point, and url-get-url-at-point.

Yes, there's some overlap.  Anything that merges them, even partly, is
good.  I.e. you could merge the functionality of ffap-url-at-point into
url-get-url-at-pointand then define ffap-url-at-pointas an
obsolete alias.

> The url lib documentation doesnt seem complete.

Indeed, it isn't.

> I suppose my question is: If I write url-jdbc, how can I make it be
> accepted by ffap? Or is there some other facility that superceedes ffap?

Feel free to make ffap use more of the URL package.
The URL package used to be a separate library, so Emacs packages
couldn't rely on it being available.  But now that it's bundled, there's
no reason to stay away from it.


        Stefan




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: jdbc urls
  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
  0 siblings, 2 replies; 10+ messages in thread
From: joakim @ 2008-06-12 16:25 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

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

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>>>> I have some rusty code lying about for jdbc urls, for
>>>> emacs-planner, but that can be changed. I would like to polish the code
>>>> and submit it for inclusion, but first some questions:
>>> 
>>>> - Is there something like this already that I didnt notice?
>>>> - Should this code go into ffap?
>>> 
>>> Shouldn't it logically go into lisp/url/url-jdbc.el instead?
>



[-- Attachment #2: url-jdbc.el --]
[-- Type: application/emacs-lisp, Size: 2840 bytes --]

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


-- 
Joakim Verona

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: jdbc urls
  2008-06-12 16:25       ` joakim
@ 2008-06-12 18:16         ` joakim
  2008-06-13 14:56         ` Stefan Monnier
  1 sibling, 0 replies; 10+ messages in thread
From: joakim @ 2008-06-12 18:16 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

joakim@verona.se writes:

> Stefan Monnier <monnier@iro.umontreal.ca> writes:
>
>>>>> I have some rusty code lying about for jdbc urls, for
>>>>> emacs-planner, but that can be changed. I would like to polish the code
>>>>> and submit it for inclusion, but first some questions:
>>>> 
>>>>> - Is there something like this already that I didnt notice?
>>>>> - Should this code go into ffap?
>>>> 
>>>> Shouldn't it logically go into lisp/url/url-jdbc.el instead?

I was a little bit quick on the send button.

I meant to as if the file looks ok, and if thats all there is to it when
adding support for a new url type?

Also, is there some library that uses url-lib to provide ffap like
functionality?


-- 
Joakim Verona




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: jdbc urls
  2008-06-12 16:25       ` joakim
  2008-06-12 18:16         ` joakim
@ 2008-06-13 14:56         ` Stefan Monnier
  2008-06-15 22:42           ` joakim
  1 sibling, 1 reply; 10+ messages in thread
From: Stefan Monnier @ 2008-06-13 14:56 UTC (permalink / raw)
  To: joakim; +Cc: emacs-devel

> 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




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: jdbc urls
  2008-06-13 14:56         ` Stefan Monnier
@ 2008-06-15 22:42           ` joakim
  0 siblings, 0 replies; 10+ messages in thread
From: joakim @ 2008-06-15 22:42 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

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

I tried to adress most of your concerns in the attached new version of
url-jdbc. 


[-- Attachment #2: url-jdbc.el --]
[-- Type: application/emacs-lisp, Size: 2676 bytes --]

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



Stefan Monnier <monnier@IRO.UMontreal.CA> writes:

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

Basically I looked at url-erc. It appears simpler to write an url-lib
like url-erc or url-jdbc than one that does fetching, like http.

Maybe I will add support for some http like protocol, if I can find one
that intrests me that isnt already done, then I can write docs.

> What do you mean by ffap-like functionality?

Something that figures out whats at point and does something interesting
with the value there, interactively.

>> (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
-- 
Joakim Verona

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2008-06-15 22:42 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2008-06-15 22:42           ` joakim

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.