fix with db locking (begin IMMEDIATE transaction)