Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@markojerkic
Created April 22, 2017 09:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markojerkic/8c6625bb3b3116973fdf8e37014b5f01 to your computer and use it in GitHub Desktop.
Save markojerkic/8c6625bb3b3116973fdf8e37014b5f01 to your computer and use it in GitHub Desktop.
Read method of CRUD
public void read (DatabaseHelper mDbHelper) {
SQLiteDatabase db = mDbHelper.getReadableDatabase();
// Define which rows you want to query
String[] projection = {
FeedEntry._ID,
FeedEntry.COLUMN_NAME1,
FeedEntry.COLUMN_NAME2
};
// Filter results WHERE "title" = 'My Title'
String selection = FeedEntry.COLUMN_NAME1 + " = ?";
String[] selectionArgs = { "Name of the table" };
// How you want the results sorted in the resulting Cursor
String sortOrder =
FeedEntry.COLUMN_NAME_SUBTITLE + " DESC";
Cursor cursor = db.query(
FeedEntry.TABLE_NAME, // The table to query
projection, // The columns to return
selection, // The columns for the WHERE clause
selectionArgs, // The values for the WHERE clause
null, // don't group the rows
null, // don't filter by row groups
sortOrder // The sort order
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment