Reading from the Database

Reading in data from SQLite is done using the query(…) method. SQLiteDatabase.query(…) has quite a lot going on. There are a few different overloads of this method. The one you will be using looks like this:

public Cursor query(
    String table,
    String[] columns,
    String where,
    String[] whereArgs,
    String groupBy,
    String having,
    String orderBy,
    String limit)

If you have dealt with SQL before, then most of these will be familiar to you as arguments of the select statement. If you have not, then you only need to worry about the ones you will be using:

public Cursor query(
    String table,
    String[] columns,
    String where,
    String[] whereArgs,
    String groupBy,
    String having,
    String orderBy,
    String limit)

The

Get Android Programming: The Big Nerd Ranch Guide, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.