Created
August 27, 2014 15:27
-
-
Save j-onathan/d16e0db0b2ec3c972c61 to your computer and use it in GitHub Desktop.
Android Code Example: SQLiteQueryBuilder (from https://www.codota.com/android/scenarios/52fcbca8da0af2dcd8f95380/android.database.sqlite.SQLiteQueryBuilder?tag=dragonfly)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public Cursor query(Uri uri, String[] projection, String selection, | |
String[] selectionArgs, String sortOrder) { | |
SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder(); | |
int uriType = sURIMatcher.match(uri); | |
switch (uriType) { | |
case SIMPLEENTITY_DIR: | |
queryBuilder.setTables(TABLENAME); | |
break; | |
case SIMPLEENTITY_ID: | |
queryBuilder.setTables(TABLENAME); | |
queryBuilder.appendWhere(PK + "=" | |
+ uri.getLastPathSegment()); | |
break; | |
default: | |
throw new IllegalArgumentException("Unknown URI: " + uri); | |
} | |
SQLiteDatabase db = getDatabase(); | |
Cursor cursor = queryBuilder.query(db, projection, selection, | |
selectionArgs, null, null, sortOrder); | |
cursor.setNotificationUri(getContext().getContentResolver(), uri); | |
return cursor; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment