since sqlite is not thread safe, we have to maintain our lock