2009/6/4 Joe Atzberger <joe.atzber...@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
_______________________________________________
Koha-devel mailing list
Koha-devel@lists.koha.org
http://lists.koha.org/mailman/listinfo/koha-devel

Reply via email to