I'm trying to implement a forking process with DBI and cannot get the database handle attribute InactiveDestroy to work. As you can see below, after I have reaped the child process with waitpid my database handle is not longer valid. Im currently using DBI 1.39 and the docs on it say that this was fixed. See DBI 1.39. I've even tried installing versions all the way up to the current 1.53 and I get the same problems. What am I doing wrong? Is it possible to do this without having to reconnect?
use strict; use warnings; use DBI; use DBU; print "$$ started\n"; my $dbh = DBI->connect('DBI:Oracle:dev', 'xxx', 'yyy', {PrintError => +1}); my $depts_sql = <<EOT; select d.id deptid from codes c, dept d where c.id = ? and nvl(d.cdt,sysdate+1) > sysdate and c.cd = d.id EOT my $depts_csr = $dbh->prepare($depts_sql); deptid($depts_csr); my $pid = fork; print "$$ pid = $pid\n"; if (!defined $pid) { print "$$ fork error\n"; } elsif ($pid == 0) { print "$$ child\n"; $dbh->{InactiveDestroy} = 1; # do something here in the child process exit; } deptid($depts_csr); # this call will succeed because the child has not + been reaped yet waitpid $pid, 0; deptid($depts_csr); # this call will fail $dbh->disconnect; sub deptid { my ($csr) = @_; $csr->execute('WVPLPRT'); print "depts="; while (my ($deptid) = $csr->fetchrow_array) { print "$deptid,"; } print "\n"; }
Here is the output
# perl problem 21754 started depts=1,10,11,13,14,15,17,18,19,2,20,21,23,27,3,30,5,9, 21754 pid = 21757 21757 pid = 0 21757 child depts=1,10,11,13,14,15,17,18,19,2,20,21,23,27,3,30,5,9, DBD::Oracle::st execute failed: ORA-01001: invalid cursor (DBD: oexfet + error) at problem line 42. DBD::Oracle::st fetchrow_array failed: no statement executing (perhaps + you need to call execute first) at problem line 44. depts=

In reply to DBI InactiveDestroy problem by mifflin

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.