FMDB: Fixed locking calls to avoid a deadlock

Fixes #500 (I think)