On Mon, Nov 29, 2004 at 05:45:07PM +0100, Hans Schou wrote:
>
> Hi Tim
>
> Before I go implement DBURL into DBI.pm you write that I should ask
> you first about it.
>
> In short, DBURL is one line string which looks like a http URL.
> A connection in DBI PostgreSQL could look like:
> $dbh = DBI->connect("dburl=pgsql://joe:[EMAIL PROTECTED]:5432/mydb/");
>
> If you think this could go into DBI, take a look at the attached file
> or the homepage with examples http://w0.dk/~chlor/dburl/
I get "Error 301 - Moved Permanently"
> What do you think?
If you change
protocol://[[user[:[EMAIL PROTECTED]:port][/[database[/]]]
to
dbi://[[user[:[EMAIL PROTECTED]:port]/driver[/[database[/]]]
then I'd consider it. Otherwise it won't scale to any db that has
a name that clashes with an already assigned URL scheme.
There are some other minor issues, but I think that's the main one.
CC'd to dbi-dev mailing list for further discussion. (Hopefully someone
will do some research to see if there's an official proposed standard in
the works for this kind of thing. I don't have time right now.)
Tim.
> DataBaseUniformResourceLocation
>
> by Hans Schou
>
> DBURL is a notation for accessing a database in a similar way as accessing
> a website on Internet. In one
> line a website can be uniqued identified - sometimes with a port number -
> sometimes with a user name and
> password.
>
> The goal with DBURL is to provide exactly the same.
>
> DBURL could be implemented with database command line utilities like psql
> for PostgreSQL or mysql for
> MySQL. Here DBURL could be provided in the environment or on the command
> line. An example for connecting
> to a local PostgreSQL database via TCP/IP on port 1234 could go like:
>
> $ export DBURL=pgsql://localhost:1234/
> $ psql
>
> Or the DBURL could be written on the command line:
>
> $ psql dburl=pgsql://localhost:1234/
>
> The same notation could be used for MySQL or other DBMS.
>
> For PostgreSQL or MySQL it is not necessary to specify the protocol as
> this is defined within the
> program. The only exception is when one wants to use SSL encryption with
> PostgreSQL it is mandatory to
> specify the protocol 'pgsqls'.
>
> If DBURL is to be used with Perl DBI it is mandatory to specify the
> protocol as DBI by default do not
> know which DBMS it should use. Because of that there is a difference of
> the minimum requirements in the
> syntax of the DBURL depending on the used program.
>
> Perl DBI
>
> The DBURL syntax for DBI should as minimum provide the protocol for the
> DBMS to be used. All other
> options will have a default value. For DBI the syntax is:
>
> protocol://[[user[:[EMAIL PROTECTED]:port][/[database[/]]]
>
> DBI should either take DBURL as an argument or from the environment. An
> example where the environment
> variable DBURL is used:
>
> $dbh = DBI->connect();
>
> An example of accessing PostgreSQL with default parameters:
>
> $dbh = DBI->connect("DBURL=pgsql://");
>
> A full example with all parameters used:
>
> $dbh = DBI->connect("DBURL=pgsql://user:[EMAIL
> PROTECTED]:5432/mydb/");
>
> The same connect string as above for MySQL:
>
> $dbh = DBI->connect("DBURL=mysql://user:[EMAIL
> PROTECTED]:3306/mydb/");
>
> Example files for DBI
>
> * [1]dburl.pl - The URL parser
> * [2]dburltest.pl - An example of use
>
> PostgreSQL
>
> When using psql from the command line some default parameters can be set
> in the environment. These
> variables are: PGPORT, PGHOST, PGDATABASE, PGUSER, and PGPASSWORD. When
> one want to use another host it
> is often necessary to change several of these variables to get the right
> connection parameters. With a
> DBURL there will be only line to change and the same line could be shared
> with Perl DBI.
>
> The syntax for PostgreSQL is:
>
> [protocol://][[user[:[EMAIL
> PROTECTED]:port][/[database[/[[table[/[column[,column...]*]]]|sql]]]]
>
> The most simpel use of DBURL with psql is an empty string. As this can not
> be shared with Perl DBI it is
> not recommended. The simple example:
>
> $ export DBURL=""
> $ psql
>
> As minimum the protocol should be specified. In that way DBURL can be used
> both by psql and Perl DBI:
>
> $ export DBURL=pgsql://
> $ psql
>
> A full example with all parameters used:
>
> $ export DBURL=pgsql://user:[EMAIL PROTECTED]:5432/mydb/
> $ psql
>
> A command line option could look like:
>
> $ psql --dburl="pgsql://user:[EMAIL PROTECTED]:5432/mydb/SELECT *
> FROM mytable"
>
> When using a UNIX socket the hostname should be omitted. It looks a little
> strange but there is no
> problem with parsing it:
>
> $ psql --dburl="pgsql://user:pass@:5432/mydb/SELECT * FROM mytable"
>
> psql could be extended to look for both the environment variable PGURL and
> DBURL but that might not be
> recommended. In this situation PGURL would have the same syntax as DBURL.
>
> In C the method for connecting is pset.db = PQsetdb(...). A similar method
> could be pset.db =
> PQsetdburl("pgsql://example.com/mydb/"); or pset.db =
> PQsetdburl(getenv("DBURL")); .
>
> Example files for PostgreSQL
>
> * [3]dburl.c - The URL parser
> * [4]dburl.h - header file
>
> The inspiration to the formal description of DBURL comes from PhpWiki. The
> syntax is not exactly the
> same regarding UNIX sockets.
>
> [5]ISO/IEC 15445
>
> References
>
> Visible links
> 1. file:///tmp/dburl.pl
> 2. file:///tmp/dburltest.pl
> 3. file:///tmp/dburl.c
> 4. file:///tmp/dburl.h
> 5. http://validator.w3.org/check/referer