Fix SQLite queries in backend.