[DB-SIG] URI syntax for database (was: [SQLObject] Re: SQLite connection - relative filename)

M.-A. Lemburg mal at egenix.com
Mon Apr 4 12:59:40 CEST 2005


Dittmar, Daniel wrote:
>>From: db-sig-bounces at python.org 
>>[mailto:db-sig-bounces at python.org] On Behalf Of Ian Bicking
>>After that it's 
>>potentially entirely up to the database driver, though of course some 
>>uniformity is nice.  Typical DSNs, from what I can tell, are parsed in 
>>an up-front manner into a set of keys and values; though maybe they 
>>sometimes include a prefix indicating database type...?  
> 
> 
> DSNs (Data Source Names) are registry keys. The entry for that key
> contains among other things the id of the ODBC driver. The string for a
> connect contains the DSN (which is evaluated by the driver manager) and
> additional connect properties (which are passed to the driver). This at
> least was the general idea, which has probably been bended since.

The format of ODBC connection strings (sometimes called DSN string
or just DSN) goes like this:

connection-string ::= empty-string[;] | attribute[;] | attribute; connection-string
empty-string ::=
attribute ::= attribute-keyword=attribute-value | DRIVER=[{]attribute-value[}]
attribute-keyword ::= DSN | UID | PWD | driver-defined-attribute-keyword
attribute-value ::= character-string
driver-defined-attribute-keyword ::= identifier

(taken from
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odbc/htm/odbcsqldriverconnect.asp;
scroll down to the comments section)

At the very least you have to provide the DSN=<name>
part of the connection string. All other parts are
optional.

>>Java has 
>>database URIs too, don't they?  But they are all like 
>>jdbc:..., correct? 
> 
> 
> Right
> 
> 
>> Of course, following that pattern you could get 
>>dbapi:jdbc:postgresql://... which feels awfully weird to me.
> 
> 
> a) I'd prefer pydbapi: as a prefix. That way, someone looking at a
> configuration file could at least get the notion that any problems might
> be related to some Python lib.
> 
> b) Using a module path instead of a DBMS product name is generally
> preferable (and seemed to be the consent so far). With the JDBC scheme,
> all relevant drivers have to be loaded into memory first, the diver
> manager then asks each if the driver would accept a specific URI. 
> 
> c) Should username and password be used similar to other protocols?
>   pydbapi:<modulepath>://[<username>:<password>@]<host>[:
> <port>/

This is not URI conformant (AFAIK): you cannot have multiple
schemes separated by colons.

pydbapi-<modulepath>://...

would work, e.g.

pydbapi-mx.ODBC.Windows://<uid>:<pwd>@sqlserver.example.com/?DATABASE=test

Looking at this URI I don't think that the URI-approach is
going to make things any easier for the user in setting up
things.

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Apr 04 2005)
>>> Python/Zope Consulting and Support ...        http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ...             http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/
________________________________________________________________________

::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! ::::


More information about the DB-SIG mailing list