From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: joakim@verona.se Newsgroups: gmane.emacs.devel Subject: Re: jdbc urls Date: Thu, 12 Jun 2008 18:25:51 +0200 Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1213288006 28979 80.91.229.12 (12 Jun 2008 16:26:46 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 12 Jun 2008 16:26:46 +0000 (UTC) Cc: emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Jun 12 18:27:29 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 1K6pe3-0002CS-MR for ged-emacs-devel@m.gmane.org; Thu, 12 Jun 2008 18:27:27 +0200 Original-Received: from localhost ([127.0.0.1]:54030 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1K6pdF-0004yX-Vu for ged-emacs-devel@m.gmane.org; Thu, 12 Jun 2008 12:26:38 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1K6pcc-0004jZ-Aw for emacs-devel@gnu.org; Thu, 12 Jun 2008 12:25:58 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1K6pca-0004io-LM for emacs-devel@gnu.org; Thu, 12 Jun 2008 12:25:57 -0400 Original-Received: from [199.232.76.173] (port=55105 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1K6pca-0004ii-F1 for emacs-devel@gnu.org; Thu, 12 Jun 2008 12:25:56 -0400 Original-Received: from iwfs.imcode.com ([82.115.149.64]:41871 helo=gate.verona.se) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1K6pca-00082M-2c for emacs-devel@gnu.org; Thu, 12 Jun 2008 12:25:56 -0400 Original-Received: from chopper (IDENT:1005@localhost [127.0.0.1]) by gate.verona.se (8.13.4/8.11.4) with ESMTP id m5CGPpmh027759; Thu, 12 Jun 2008 18:25:51 +0200 In-Reply-To: (Stefan Monnier's message of "Wed, 04 Jun 2008 22:11:54 -0400") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux) X-detected-kernel: by monty-python.gnu.org: Linux 2.4-2.6 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:99019 Archived-At: --=-=-= Stefan Monnier 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? > --=-=-= Content-Type: application/emacs-lisp Content-Disposition: attachment; filename=url-jdbc.el Content-Transfer-Encoding: quoted-printable ;;; url-jdbc.el --- jdbc url support ;; Copyright (C) 2008 Free Software Foundation, Inc. ;; Author: Joakim Verona ;;; Commentary: ;;=20 ;; url-jdbc enables parsing of some jdbc urls, and connecting with ;; emacs sql mode to the database described by the url. ;;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.=20 ;;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 ;; jdbc:postgresql:database ;; jdbc:postgresql://host/dabase ;; jdbc:postgresql://host:1234/dabase ;; jdbc:postgresql:database?user=3Dme ;; jdbc:postgresql:database?user=3Dme&password=3Dmypass ;; jdbc:postgresql://localhost/pgdatabase?user=3Ddemo&password=3Ddemo ;; jdbc:mysql://localhost/database ;;(url-jdbc (url-generic-parse-url (url-get-url-at-point))) ;(url-parse-query-string) ;;; History: ;;=20 (require 'url-vars) (require 'url-util) (require 'url-parse) ;;; Code: (defun url-jdbc (url-orig) (let* ( (url (url-generic-parse-url (url-filename url-orig)));see comment= ary to understand this (driver (url-type url)) =20=20=20=20=20=20=20=20=20 (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)) ) ;;get the url query attributes (if (string-match (regexp-quote "?") rest) (setq headers-start (match-end 0) args (url-parse-query-string (substring rest headers-start nil) t t))) =20=20=20=20 ; (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) (url-jdbc-connect driver sql-server sql-port sql-database sql-user sql-= password args) ) ) (defun url-jdbc-connect (driver sql-server sql-port sql-database sql-user s= ql-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))))) =20=20 (cond ((string=3D "postgresql" driver) (sql-postgres)) ((string=3D "mysql" driver) (sql-mysql)) (t (message "no driver matched")) ) ) (provide 'url-jdbc) (provide 'url-jdbc) ;;; url-jdbc.el ends here --=-=-= -- Joakim Verona --=-=-=--