Fix SQLite queries