I have a database from which I want to query and display only that data which has one type of similar field..
Say all rows have a day(Mon to sun) in them… I want to display all the rows that have Monday as the day…
I have used SimpleCursorAdapter to display all the rows from my database…
Basically, I want to know how i can query in SimpleCursorAdapter to display rows of the data having only say, Monday as the day…
Any help is appreciated…:)
The following code enables me to display all the data from my data base…
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.testlayout2);
listContent = (ListView)findViewById(android.R.id.list);//.id..list);
mDB = new DataSource(this);
mDB.open();
cursor = mDB.queueAll();
String[] from = new String[]{
MySQLiteHelper.KEY_START, MySQLiteHelper.KEY_END,
MySQLiteHelper.KEY_SUBJECT, MySQLiteHelper.KEY_LOC,
MySQLiteHelper.KEY_TEACHER };
int[] to = new int[] {R.id.tvStart, R.id.tvEnd,
R.id.tvSub, R.id.tvLoc, R.id.tvTeacher };
cursorAdapter = new SimpleCursorAdapter(this, R.layout.row, cursor,
from, to);
listContent.setAdapter(cursorAdapter);
listContent.setOnItemClickListener(listContentOnItemClickListener);
}
}
I want the query to be like this..
Cursor cursor = db.query(table, null, "day like " + "'%Monday%'",null,
null, null, null);
Got that… Sorry for the trouble. Please tell me where i am going wrong with this though..
I made this in the code to query the day and sort ascending by time..
public Cursor queryDay(String days) {
Cursor cursor = mDatabase.query(DATABASE_TABLE, mAllColumns, "day like " +
days, null, null, null, Database.KEY_START + " ASC");
if (cursor.moveToNext()) {
return cursor;
}
return cursor;
}
However, I get this error,
android.database.sqlite.SQLiteException: no such column: Thursday: ,
while compiling: SELECT _id, day,start_time, end_time, sub, location,
teacher FROM subjectTable WHERE day like Thursday ORDER BY start_time ASC
I am calling this like this..
Cursor cursor = mDB.queryDay("Thursday");
startManagingCursor(cursor);
This solves the second part of the question..