Somk
Somk

Reputation: 12047

SQLite Count Rows Android

I think I have got a script that will work for this, but im struggling to get the value out into a variable and post it into a textview and eventually compare it to another integer.

    private SQLiteDatabase mDatabase;

private long fetchPlacesCount() {
    String sql = "SELECT COUNT(*) FROM " + DB_TABLE;
    SQLiteStatement statement = mDatabase.compileStatement(sql);
    return (int) statement.simpleQueryForLong();

}

Upvotes: 1

Views: 11072

Answers (1)

lawal
lawal

Reputation: 992

Why don't you use the provided DatabaseUtils class for the query.There is something similary here Android SQLite Cursor out of bounds exception on SELECT count(*) FROM table

Upvotes: 4

Related Questions