Use explicit locking around sqlite transactions

Seriously fuck sqlite