Don't use Read/WriteDB inside a cursor loop.

LMDB doesn't allow multiple transactions per thread. Opening a cursor
opens a transaction, and so does Read/WriteDB. So, either re-use values
from cursor, or populate a sequence with keys, and then lookup the
individual values in a separate loop.

Note: Previously, the WriteDB code reused the transaction from an open
cursor, but that is making the entire LMDB driver not thread-safe.