Defensive coding against sqlite bug. Closes #245