Re: Does an explicit database close method exist?
[prev]
[thread]
[next]
[Date index for 2004/09/21]
On Sep 20, 2004, at 10:45 AM, Carl Johnstone wrote:
>
>
>> Class::DBI->set_db( 'Main', "dbi:Oracle:$db" );
> [snip]
>> # Return all database handles
>> @dbh = SOME_DBI_CLASS->db_handles;
>>
>> # I only have interest in first because I only have one DB connection.
>> $dbh = $dbh[0];
>>
>> $dbh->disconnect;
>
> If you know you're only ever going to have one DB connection, you
> should be able to access it through name - which is probably better:
>
> __PACKAGE__->db_Main->disconnect;
>
> Alternatively loop through all and nuke them from orbit:
>
> foreach my $dbh (__PACKAGE__->db_handles) {
> $dbh->disconnect;
> }
>
Carl,
Yes, I would agree, except that I wrapped a ClassDBI class around
Class::DBI. Its sole purpose in life is to provide a default set of
arguments to Class::DBI->set_db. From inside our applications we can
write "ClassDBI->set_db" without arguments or alternatively provide
named arguments for overriding the defaults; the later will be rare.
If I ever need to change the default arguments, I only need to change
ClassDBI::set_db and not all our applications. Since I could change
the default "Main" to something else, I didn't want to hardcode
__PACKAGE__->db_Main->disconnect into the application. Maybe there's a
better solution to what I am trying to achieve, but that's where I'm at
now.
-Bob