> From: Vladislav Safronov [mailto:[EMAIL PROTECTED]]

> What can you say about this code? is it ok (overwriting 
> previous handle)?
> 
> ==
> sub foo {
>       my $dbh = shift;
> 
>       my $sql1 = "select *...
>       my $sql2 = "select *...
> 
>       my $sth = $dbh->prepare($sql1);
>       $sth->execute;
>       .. fetch some data.
> 
>       # should be $sth->finish inserted??
> 
>       $sth = $dbh->prepare($sql2); # we overwrite previous 
> handle saved in $sth
> ..
>       $sth->execute;
>       .. fetch some data.
>       return;
> }
> ==

$sth->finish should be inserted if (and ONLY if) the C<...fetch some data>
does NOT fetch ALL data in the select. If you do some thing like:
   while (my $r=$sth->fetchrow_arrayref) {
     .. handle data;
   }
there is no reason to call finish, but if you do
   while (...$sth->fetch..) {
       ....
       last if <some condition>;
   }
you will have to call finish, but I would reccomend using
another name for the second statement (that would help
the poor sod who will try to understand this in a years time :)

Henrik

Reply via email to