sqlite: harden multithreaded queries