mce has asked for the wisdom of the Perl Monks concerning the following question:
I have a question in follow up of threads 119171 and 103323. I have exactly the same problem as I store my dbi object as an attribute of my object. For example.
Now I want to commit the transactions in a DESTROYsub opendb { my $self=shift; $self->{_dbh}=DBI->connect(...); return $self->{_dbh}; }
The strange thing is that warn is not called in every script script, although I am sure that I call opendb everytime. I think that the _dbh attribute is destroyed before $self itself is destroyed!sub DESTROY { my $self=shift; local($@); if ( $self->{_dbh} and $self->{_dbh}->ping ) { warn; ## to debug $self->{_dbh}->commit; $self->{_dbh}->disconnect; } }
This problem is noted before, and a forced $self->{_dbh}->commit is the best solution. But they mention also that this problem will be solved in future versions of perl.
Now, is this already solved? I use 5.005_03 on solaris (which is not installed nor maintained by me).
And is there a good way of debugging OO problems like this?
(using some Devel package?)
Thanks for your assistance,
---------------------------
Dr. Mark Ceulemans
Senior Consultant
IT Masters, Belgium
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: DESTROY and DBI
by krisahoch (Deacon) on Aug 27, 2002 at 12:38 UTC | |
by RMGir (Prior) on Aug 27, 2002 at 12:48 UTC | |
by mce (Curate) on Aug 27, 2002 at 13:26 UTC | |
by RMGir (Prior) on Aug 27, 2002 at 14:01 UTC |