Thread: Perl & DBI/DBD::Pg confusion with finish
Hello - When using DBD::Pg through DBI, can somebody tell me if it is necessary to be calling the $sth->finish routine? The DBI.pm documentation states that there is no need to call it if you call $sth->fetchrow_xxxref until the rows are exhausted - finish should get called automatically, and $sth->{'Active'} should change to false. However, if I don't call $sth->finish after reading all rows, then $sth->{'Active'} is still true - which makes it useless to test. Also, it seems that if I call $sth->fetchrow_hashref (or $sth->fetchrow_arrayref) until I exhaust the rows and get an undef, I can actually then call it again and it will start over from the first row in the result set (is this supposed to happen?). Which, if for some reason you do this, can send you into an endless loop of rereading the result set. By all appearances in my code, it does not seem necessary to call finish, and I get no errors even if I intentionally try to force one by starting a new query before I have read all the rows from the first (similar to the example in DBI.pm). However, the interaction with the Active attribute, and who knows what else, does not seem to work as implied in the docs. Anybody have any experience with this, with postgres or otherwise? I am hoping that my resulting code will be portable, but I have not yet used DBI with another database system, so it is rather important that whatever works with DBD::Pg will also work with others! --d
On Thu, 1 Mar 2001, David Lynn wrote: > > Hello - > > When using DBD::Pg through DBI, can somebody tell me if it is necessary > to be calling the $sth->finish routine? The DBI.pm documentation states > that there is no need to call it if you call $sth->fetchrow_xxxref until > the rows are exhausted - finish should get called automatically, and > $sth->{'Active'} should change to false. We've found that DBD::Pg doesn't do this. So we either have to call $sth->finish every time, or prepare the statement with $dbh->prepare_cached() and passing the active flag as true. It shouldn't be this way, but it is. HTH, David
> > When using DBD::Pg through DBI, can somebody tell me if it is > > necessary to be calling the $sth->finish routine? The DBI.pm > > documentation states that there is no need to call it if you call > > $sth->fetchrow_xxxref until the rows are exhausted - finish should get > > called automatically, and $sth->{'Active'} should change to false. > > We've found that DBD::Pg doesn't do this. So we either have to call > $sth->finish every time, or prepare the statement with > $dbh->prepare_cached() and passing the active flag as true. It shouldn't > be this way, but it is. What are the consequences of not calling ->finish()? I have several apps using DBD::Pg, and I don't think I've used it at all... John -- # John Madden weez@freelists.org ICQ: 2EB9EA # FreeLists, Free mailing lists for all: http://www.freelists.org # UNIX Systems Engineer, Ivy Tech State College: http://www.ivy.tec.in.us # Linux, Apache, Perl and C: All the best things in life are free!
> What are the consequences of not calling ->finish()? I have several apps > using DBD::Pg, and I don't think I've used it at all... There don't appear to be any fatal consequences - all queries appear to work fine. However, certain things such as the $sth->{'Active'} attribute cannot be relied upon. I guess we will just write this off as another "feature" to ignore! Thanks for the input, everybody. --David
On Fri, 2 Mar 2001, John Madden wrote: > What are the consequences of not calling ->finish()? I have several apps > using DBD::Pg, and I don't think I've used it at all... It just means that the statement handle is marked finished, and if you use it again, it won't issue a warning saying that it's not. HTH, David