Fixed sqlite code to work better with multithreaded webui code