DeaconBlues has asked for the wisdom of the Perl Monks concerning the following question:
I am creating a Perl Module that has atleast 3 sub routines that could be called externally. One of these routines calls all the rest of the routines. So you could get a routine to run in two ways: by calling it directly or by calling the "all" routine.
Now here is my problem: Each routine connects to the database using DBI or the "all" routine connects and passes the database handle along. I am trying to determine when I should disconnect from the database when calling the routines in the 2 scenarios.
Here are some code snippets
sub make_all_reports { # connect to the database my $dbh = &_get_dbh; &make_summary_report($dbh); &make_report1($dbh); &make_report1($dbh); ... # close the database connection $dbh->disconnect; # return happy and healthy return (1); }
That was for reference, my problem is in the next routine.
sub make_report1 { # connect to the database my $dbh = shift; $dbh = &_get_dbh if (!defined($dbh)); ... my $caller = caller(1); # close the database connection if opened here $dbh->disconnect if (!defined $caller); # return happy and healthy return (1); }
OK, so I need the conditional to work better on the database disconnect. I need to only disconnect if the $dbh was not passed in as a argument from a caller routine. If someone calls this routine from a different package (even main:: ?) it could break.
Any help you could provide would be wonderful, thank you
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: DBI: $dbh-disconnect; yes, now, now, but not now!
by stephen (Priest) on Mar 15, 2001 at 01:15 UTC | |
by DeaconBlues (Monk) on Mar 15, 2001 at 21:19 UTC | |
|
Re: DBI: $dbh-disconnect; yes, now, now, but not now!
by reyjrar (Hermit) on Mar 15, 2001 at 02:48 UTC | |
|
Re: DBI: $dbh-disconnect; yes, now, now, but not now!
by Masem (Monsignor) on Mar 15, 2001 at 01:19 UTC | |
|
Re: DBI: $dbh-disconnect; yes, now, now, but not now!
by turnstep (Parson) on Mar 15, 2001 at 02:42 UTC |