[Koha-devel] Avoid $sth->finish
John Beppu
john.beppu at liblime.com
Wed Jun 10 18:28:20 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.
>
>
One way to avoid this problem is to not even create an $sth.
For INSERT, UPDATE, and DELETE statements, I find that a *
$dbh->do($statement)* is often sufficient. (The do() method can take bind
variables, too.)
For SELECT statements, I just use *$dbh->selectall_arrayref($statement, {
Slice => {} }, @bind_variables)*. This will give me what I want in one shot
without having to do the prepare/execute/fetchrow_hashref dance. AND
there's no $sth for me to accidentally call finish() on, either. If you're
pretty sure the result set isn't going to be huge, taking this approach will
also save you from a lot of unnecessary typing.
----
A long time ago, I read an essay on Forth, and it had a quote that really
stuck with me. It said that *the best way to solve a problem is to
completely avoid it.* Structure the system such that the problem can't even
exist. I really liked that.
Buckminster Fuller <http://en.wikiquote.org/wiki/Buckminster_Fuller> (who
was not a programmer (but who was a great man)) had a similar system design
aesthetic. He was all about designing systems that made it impossible for
certain problems to exist. To me, this is a profound and powerful
problem-solving strategy, and this seemed like a good time to share it w/
the rest of you. :)
--beppu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/koha-devel/attachments/20090610/cbfc9bda/attachment-0002.htm>
More information about the Koha-devel
mailing list