Although I've been doing lots of work with SQL over the years, I've never
done anything with stored procedures.  While reading a book on MySQL stored
programs, I'm struck by the fact that the common method of iterating through
a resultset using a cursor requires doing "exception-based branching" (a NOT
FOUND handler).  Typically, in conventional programming languages, doing
exception-based branching is considered very bad practice.  It seems,
however, that the tools available in a PSM limits you to this strategy, in
the common cases.

It occurred to me, however, that another way to do this would be to "UNION"
in a hardcoded row of at least one "impossible" hardcoded value (sometimes
called a sentinel) that is used for checking for the last row (or in this
case, one past the last row of real data).  This would allow for detecting
the end of the resultset without using exception-based branching.

The important question is, is it even worth it?  Is exception handling in a
MySQL PSM more expensive than normal processing, like it's considered to be
in other languages, like Java?  If this works, would it make the resulting
code harder to understand than the conventional strategy?  Is this a
deranged idea?

Reply via email to