On Thu, Jul 12, 2001 at 11:56:11PM -0400, Sterin, Ilya wrote:
> 
> 
> > -----Original Message-----
> > From: Michael A. Chase [mailto:[EMAIL PROTECTED]]
> > Sent: Thursday, July 12, 2001 6:21 PM
> > To: 'RICHARD A. NAKROSHIS (Contractor) '; 'DBI User's Mailing List '
> > Cc: Sterin, Ilya
> > Subject: Re: Error on ->disconnect?
> >
> >
> > This is a problem that happens in Win32 if you reach global
> > destruction with
> 
> Yes I remember that, but I believe it had a different error, something
> regarding an disconnecting while there are still active handles?  This
> message is stating that it's trying to call execute on a undefined handle.
> I still believe it's the finish call, take a look at his code, I left out
> irrelevant stuff...

The error message which the original poster complained about is:

  (in cleanup) Uncaught exception from user code:
  Can't call method "FETCH" on an undefined value at
    C:/Perl/site/lib/Win32/TieRegistry.pm line 1486, <> line 4 during global
    destruction.
  Win32::TieRegistry::DESTROY('Win32::TieRegistry=HASH(0x22292a0)') called
    at ora-test.pl line 0
  eval {...} called at ora-test.pl line 0


As Michael said, this error is specific to Win32, and the way to avoid it
is to undef the database handle after disconnecting.


>       while (@data = $sth->fetchrow_array()) {
>               my $pn_id = $data[0];
>               my $last_name = $data[1];
>               my $first_name = $data[2];
>               my $middle_name = $data[3];
>               print "\t$pn_id: $first_name $middle_name $last_name\n";
>       }
> 
>       if ($sth->rows == 0) { print "No names matched '$queryname'.\n\n"; }
> 
>       $sth->finish;
> 
> ### This will finish and disallocate the $sth handle, so when this loops
> again it will try to call execute on it, but it's no longer valid????  Am I
> getting this correct.  I believe this is what finish does, is disallocates
> the resources for that handle.

This isn't quite right.  The statement handle in this code has an implicit
finish when $sth->fetchrow_array() is called after the last row has been
returned.  An explicit call to $sth->finish() is redundant.

In fact, $sth->finish() does *not* disallocate the resources for a handle.
Rather, it disallocates the resources for the current execution of the
handle.  This is useful when you don't want to fetch all the rows.  You can
call $sth->execute() after calling $sth->finish(), to select from the
beginning again.


Here's a silly example that fetches the first two rows for two different
people, and ignores any other rows:

$sth = $dbh->prepare(<<"EndOfSQL");
  SELECT info
  FROM   people
  WHERE  name = ?
EndOfSQL

for $name ('Joe', 'Bob') {

  $sth->execute($name);

  $first{$name}  = $sth->fetchrow_array();
  $second{$name} = $sth->fetchrow_array();

  $sth->finish();

}


Ronald

Reply via email to