I'm working on Android app that let the user add some data and then do querys on the data, Example : User can add some doctors informations like (Name, phone, city etc...) then the user can query the doctors database to retive the doctors in a spacific parameters for exmaple city.
I have this code :
@Override
public Cursor query(Uri uri, String[] projection, String selection,
String[] selectionArgs, String sortOrder) {
SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
qb.setTables(DOC_TABLE_NAME);
switch (uriMatcher.match(uri)) {
case DOC:
qb.setProjectionMap(DOC_PROJECTION_MAP);
break;
case DOC_ID:
qb.appendWhere( _ID + "=" + uri.getPathSegments().get(1));
break;
default:
throw new IllegalArgumentException("Unknown URI " + uri);
}
if (sortOrder == null || sortOrder == ""){
sortOrder = _ID;
}
Cursor c = qb.query(db, projection, selection, selectionArgs,
null, null, sortOrder);
c.setNotificationUri(getContext().getContentResolver(), uri);
return c;
}
What should i add to the cases the retiver a doctors on more than one parameter example : id, name, city. should i add this :
case DOC_ID_NAME_CITY:
qb.appendWhere( _ID + "=" + uri.getPathSegments().get(1));
qb.appendWhere( Name + "=" + uri.getPathSegments().get(2));
qb.appendWhere( City + "=" + uri.getPathSegments().get(3));
break;
Also how to call it ?
thanks :)
Aucun commentaire:
Enregistrer un commentaire