I have a query that gets data from an sqlite database based on the Day value using a where clause, The data i’m getting is for ‘Monday’ this data is then populated into a listview. In addition to this i want to order the data by the time in ascending order to form a list with all events on monday from the earliest to latest Start times.
Query by day:
public Cursor getMonday () {
String Monday = "Monday";
return db.query(
DATABASE_TABLE,
new String[] { KEY_ID, KEY_LESSON, KEY_DAY, KEY_START, KEY_END, KEY_LOCATION},
KEY_DAY + "=?",
new String[] {Monday},
null, null, null);
}
I’ve tried:
public Cursor getMonday () {
String Monday = "Monday";
return db.query(DATABASE_TABLE,
new String[] {KEY_ID, KEY_LESSON, KEY_DAY, KEY_START,KEY_END, KEY_LOCATION},
KEY_DAY + "=?",
new String[] {Monday},
null, null, null,
KEY_START + " ASC");
}
This would usually work but i imagine that the WHERE clause and order by are not in the right order and i dont know how to make them work in unison. Could someone please advise? Thanks.
This is the error im getting:
01-28 14:24:02.738: E/AndroidRuntime(1672): FATAL EXCEPTION: main
01-28 14:24:02.738: E/AndroidRuntime(1672): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.unischeduler/com.example.unischeduler.ScheduleActivity}: java.lang.IllegalArgumentException: invalid LIMIT clauses:Start ASC
Your argument order is incorrect, try this:
EDIT Proposal to order by hh:mm format:
Take a look to SQLite Date and Time Functions and maybe you could try (I haven’t tested it) something like this: