On 2004-12-08 10:21:35 +1300, Sam Vilain wrote:
> Orton, Yves wrote:
> >DBD::Ingres does something similar. DBD::Oracle appears to be closer to
> >Sybase/MySQl:
> >"dbi:Oracle:host=myhost.com;sid=ORCL"
>
> Normally you don't bother with connection parameters with Oracle at all:
>
> DBI->connect("dbi:Oracle:", "database", "password");
>
> Instead, you configure which logical Oracle installation that you want
> with an environment variable.
For some values of "normally". I don't do that, because I have different
perl scripts which connect to different databases. Having change the
TWO_TASK variable before invoking these scripts would be a major hassle.
Also some of of my scripts connect to several databases.
> I think that this information should be removed from most programs
> altogether.
Agreed.
> They should just have to specify a logical data source
> (possibly including a schema version), then a module with a config file
> maps that to a set of connection parameters.
That's what I do.
Here is a snippet from one of my programs:
=head2 new(%opts)
Create a new UsrAdm object (basically a handle for the database
connection).
[...]
Options:
=over
=item credential_file
The file containing the credentials for connecting to the database. It
can be an absolute path name or relative to ~/.dbi. If it is not set,
the environment variable DBI_CREDENTIAL_FILE is used instead, or
~/.dbi/default, if that isn't set either. The file should contain a
single line with the data source, the username and the authentication
data (password) separated by white space.
=back
=cut
sub new {
my ($class, %opts) = @_;
my $self = {};
my $cred_file = $opts{credential_file} || $ENV{DBI_CREDENTIAL_FILE};
if (! defined($cred_file)) {
$cred_file = "$ENV{HOME}/.dbi/default";
} elsif ($cred_file !~ m{/}) {
$cred_file = "$ENV{HOME}/.dbi/$cred_file";
}
$self->{dbh} = DBI->connect(_read_cred($cred_file),
{ RaiseError => 1, AutoCommit => 0 });
hp
--
_ | Peter J. Holzer | If the code is old but the problem is new
|_|_) | Sysadmin WSR / LUGA | then the code probably isn't the problem.
| | | [EMAIL PROTECTED] |
__/ | http://www.hjp.at/ | -- Tim Bunce on dbi-users, 2004-11-05
pgpqZzy3WZa2i.pgp
Description: PGP signature
