Forum OpenACS Development: Re: db_multirow and db_foreach -unclobber

Collapse
Posted by Tom Jackson on

An interesting point is that db_multirow, without a foreach block, doesn't clobber the local vars. This means the original intent of db_multirow was to not create these vars in the local context. I believe that the foreach code block was added recently to make it possible to do per row processing. Given that the new db_multirow combines features of the old nonclobbering db_multirow and the clobbering db_foreach, I can see the reason behind your original proposal as it applies to db_multirow.

For db_multirow, the question of what should be the default (-clobber/--unclobber) is still important. If you look at ad_page_contract properties, the multirow is usually only specified as the array name, not the individual column names. If you add a foreach block to the db_multirow for the purpose of, for example, adding a calculated column to each row, your intent is not to have to deal with all these variables that now exist, and possibly have overwritten, your local variables. I'm almost to the point of thinking that -unclobber should be the default, so that things match up with the original db_multirow behavior.

A similar intent could be applied to db_foreach. Many times I have used db_foreach for a purpose not related to setting local variables, and never for setting the variables that are reset for each iteration of the loop.

Lars, I'm sorry that I misintrepreted your reasons for the changes.