db: get exclusive lock in *::foreach() commands

Since 8d37878ed014b94640a92e0e06e9d6e6507fabd5
("jsvm: allow to change values inside *FOR js code") we allow clients to
change data using user-specific scripting, and it means that we are
definitely need an exclusive lock.