Forum OpenACS Q&A: Response to nice little tcl gotcha

Posted by Titi Ala'ilima on
I tend to over-brace, myself. (I greatly prefer bracing SQL rather than quoting it when there is no need for evaluation.)

Anyway, this is a wonderful example for teaching Tcl newbies how the interpreter works. Understanding when things are evaluated is of vital importance.

Speaking of which, one annoying pseudo-Tcl construct is the db_foreach. I'm sure some of you have encountered the problem with trying to return from within something like this, as it's actually evaluating in a different context. I've found you can use a "return -code return", but I also found that this doesn't work inside the if_no_rows clause. I haven't taken the time to look too deeply into it, but my guess is it evaluates that bit two contexts down, so the "return -code return" only exits out of two contexts but not the context in which it looks like you're calling it.