SQLite query method