[Koha-devel] Avoid $sth->finish

Jesse pianohacker at gmail.com
Fri Jun 5 19:12:53 CEST 2009


2009/6/4 Joe Atzberger <joe.atzberger at liblime.com>

> Kohackers --
>
> I want to mention this because I've seen a lot of recent patches still
> using the old style of code calling $sth->finish() explicitly.  I know a lot
> of the codebase still does this internally, but for Koha such usage is
> almost always wrong.
>
> If this were just my personal contention, I would couch this in terms of an
> RFC to deprecate the usage.  But we don't get a choice here: DBI is telling
> us "don't do it".
>
> Please refer to the DBI perldoc<http://search.cpan.org/%7Etimb/DBI-1.608/DBI.pm#finish>
> :
>
> The finish method is rarely needed, and frequently overused, but can
> sometimes be helpful in a few very specific situations to allow the server
> to free up resources (such as sort buffers).
>
> When all the data has been fetched from a SELECT statement, the driver
> should automatically call finish for you. So you should *not* normally
> need to call it explicitly *except* when you know that you've not fetched
> all the data from a statement handle. The most common example is when you
> only want to fetch one row, but in that case the selectrow_* methods are
> usually better anyway. *Adding calls to finish after each fetch loop is a
> common mistake, don't do it, it can mask genuine problems like uncaught
> fetch errors.*
> That last sentence is the most concrete and important (hence my bolding).
> Moral of the story: don't do it.  Or if you think you have to, at least
> comment why, like:
> $sth->finish();  # FIXME: leaving data unfetched, should rework query
>
> --
> Joe Atzberger
> LibLime - Open Source Library Solutions
>
> _______________________________________________
> Koha-devel mailing list
> Koha-devel at lists.koha.org
> http://lists.koha.org/mailman/listinfo/koha-devel
>
>
I've wondered about this myself, since Perl, being a dynamic language,
should have some sort of destructor support.

Thanks for looking into this, I'll try to avoid it in the future.

-- 
Jesse Weaver
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/koha-devel/attachments/20090605/12fe6907/attachment-0002.htm>


More information about the Koha-devel mailing list