Gossamer Forum
Home : General : Perl Programming :

Destroying a database handle

Quote Reply
Destroying a database handle
If I have a module that returns a statement handle to be used somewhere else, what is the best way to finish() and disconnect() or is it done automatically?

eg....

Module1:

my $sth = $DB->table('Foo')->select;

SQL Module:

sub select { ...code... return $sth }

When I've done what I want in Module1 can I just forget about $sth or should I have a method in the SQL module to destroy the database handle?

I heard somewhere that DBI destroys it automatically. Is that right?
Quote Reply
Re: [Paul] Destroying a database handle In reply to
you only need to call finish() if you for some reason you do not process all of your results from start to finish.

--Philip
Links 2.0 moderator
Quote Reply
Re: [King Junko II] Destroying a database handle In reply to
What about $dbh->disconnect() ?
Quote Reply
Re: [Paul] Destroying a database handle In reply to
You should call disconnect at the end of your program. You can do this with an END block if the database handle is global, or a DESTROY sub if it's in a module.

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] Destroying a database handle In reply to
Thanks. It works.

Last edited by:

Paul: Mar 30, 2002, 9:47 AM
Quote Reply
Re: [Paul] Destroying a database handle In reply to
Hi,

$self will be the first argument passed in. Perhaps you already called disconnect() on the database? For some reason $self->{dbh} is undefined.

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] Destroying a database handle In reply to
Sorry I edited my post above, it was END that caused the error, DESTROY works fine...thanks.