Hi All,

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.

sub opendb { my $self=shift; $self->{_dbh}=DBI->connect(...); return $self->{_dbh}; }
Now I want to commit the transactions in a DESTROY
sub DESTROY { my $self=shift; local($@); if ( $self->{_dbh} and $self->{_dbh}->ping ) { warn; ## to debug $self->{_dbh}->commit; $self->{_dbh}->disconnect; } }
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!

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


In reply to DESTROY and DBI by mce

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.