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: doeAnd 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=doeNo 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.
