Wrap a transaction around all code that does a get-update-put.

Now that transactions enforce a single writer, this will prevent race
conditions that overwrite another thread's write.
Minor cleanup of CBLDatabase+Attachments