Forum OpenACS Development: Re: db_multirow and db_foreach -unclobber

Collapse
Posted by Jonathan Ellis on
I don't see how.  It's neither obscure, since db_1row et al necessarily set variables in parent scope, nor bad form when you can't do what you need to do in the foreach.  For instance, if you select foo from bar order by foo and want to see if the last foo has a value over some cutoff point, what other options do you have?  Manually setting some variable(s) inside the foreach body to what you are interested in, with each iteration, just so it is preserved afterwards?  Forcing developers into that for the sake of some misguided purity is stupid.
Collapse
Posted by Jarkko Laine on
I can see your point about the cutoff point, Jonathan.

However, I don't think comparing db_1row et al which return just one row to these multirow procs is worthwhile. It's obvious what you get from db_1row, but it's definitely not that intuitive that you get the values of last db row in local variables when you use db_multirow or db_foreach. Like Peter, I wouldn't assume to get local variables overwritten.

I don't think this would be "Forcing developers into that for the sake of some misguided purity". Now we are forcing developers to save their local variables always when they use db_multirow or db_foreach if they aren't sure there's no columns in the query with the same name. I think that instead of misguided purity we are talking about which way would be more useful. I would take Peter's side but it's just my opinion.

Maybe there could be an additional code block for the last row of db_foreach for this, if it's really needed. Or a -clobber parameter in the spirit Lars mentioned.