I have this as my query:
public Cursor getQuests(int level) {
final String[] columns = new String[] {KEY_ID, "title", "minUC", "maxUC", "xp", "ep", "request", "loot", "level", "numHits", "numHitsReq"};
return db.query(QUESTS, columns, "level<=\"" + level + "\"", null, null, null, KEY_ID + ", level");
}
So, I have entries up to level 10 in my database. This query works normally up to a point, while players level is less than 10 everything works as expected, however when player is level 11 or higher the query only returns rows where level = 1.
When I remove the escaped quotes around level it returns an empty cursor. Am I doing something wrong?
Your problem is most likely due to the fact the LEVEL column in the database is text/string. Then you are comparing it to another string:
However if you are to compare the values, you’ll get the expected results
Change the database column to INTEGER and remove the quotes around level in your query – and you’ll be fine.