Re: DBIx::DBH - Perl extension for simplifying database connectio ns

From: Adriano R. Ferreira (ferreira_at_triang.com.br)
Date: 12/08/04


Date: Tue, 07 Dec 2004 22:58:29 -0300
To: dbi-users@perl.org


> Orton, Yves wrote:
> DBI->connect("dbi:Oracle:", "database", "password");

If DBI->connect() would accept a hash ref with some meaningful keys,
I think the bare minimum can be 'url', 'user', 'pass' (or 'password').

So the line above would read

        DBI->connect({ url => 'dbi:Oracle:', user => 'database', pass =>
'password' });

or even better reading this from an external source (like a XML or YAML
file) which isolates the source code of configuration parameters.

        use XML::Simple;
        my $params = XMLin('boo.xml');
        my $dbi_params = $params->{connection}->{first_db};
        my $conn = DBI->connect($dbi_params); # DBI

(or if you prefer YAML

        use YAML qw(LoadFile);
        my $params = LoadFile('boo.yml');
        my $dbi_params = $params->{connection}->{first_db};
        my $conn = DBI->connect($dbi_params); # DBI
) But this have nothing to do inherently to DBI but marked lines.

I think that is simple enough and maybe useful. The same piece
of code before can be used without change for the most various
databases, with any parameter you care about. For example, opening
a Firebird database connection with autocommit off
and specifying a date-to-char translation default:

        ---
        url: 'dbi:Oracle:'
        user: sysdba
        pass: masterkey
        AutoCommit: 0
        params:
                ib_timestampformat => '%m-%d-%Y %H:%M'

The first level is for parameters that make sense for most databases.
If it doesn't make sense, don't use it. Just like some ODBC sources
won't care about users and passwords.

The point of this thread is that url's are bad because each one has
its style. So if the driver author gives support one could say

        ---
        host: mysqlhost
        port: 8888
        database: dadada
        user: joe
        pass: doe

And there are those who don't care to consult a notebook for how
to write a DSN and will use just

        ---
        dsn: host=mysqlhost;port=8888;database=dadada;user=joe;pass=doe

No one would force authors to comply with that, but with patches
and with suggestions it could be done. So I think that
accepting a hash ref as the only parameter in DBI->connect()
is the first step. "But it is too little! Why don't you say:

        DBI->connect($params->{url}, $params->{user}, $params->{pass}, $params)

Answer: Laziness. My poor 2 cents.

Best regards,
Adriano Ferreira.



Relevant Pages

  • Re: What would be my best alternative to MS Works?
    ... For example, if this Power Mac ... I found a Time Billing template for FileMaker that might do the ... but didn't care for it for this purpose. ... databases, and also build databases for various organizations. ...
    (comp.sys.mac.apps)
  • Re: how to make dates without timezones?
    ... support it? ... right care. ... to use other databases than Oracle/PostgreSQL. ... But you will also note that both databases have Date types that only ...
    (comp.lang.java.programmer)
  • Re: help needed please/ database grid lines
    ... anyone help please - I have printed the grid lines in earlier databases. ... tiles, I now have a washbasin in the bathroom with taps and ... You two take care as well :-) ...
    (uk.people.silversurfers)
  • Re: OO Re: About Entity-Relationship Diagram in BDS 2007
    ... I don't like applications where DA controls are connected directly to databases. ... I don't care whether such code is automatically generated or not. ...
    (borland.public.delphi.non-technical)