Android and stuff
Android: Get number of rows in SQLite Database Table
Here’s a little function from my Database Adapter class in the app I’m working on. It returns the number of rows in the “Places” table from my database.
It does this using a SQLiteStatement object, much simpler and cleaner than getting a Cursor using SQLiteDatabase.rawQuery().
A SQLiteStatement can be used for database queries that return “1×1 result sets”, that is one row with one column – a single value.
private static final String DB_TABLE_PLACES = "Places";
private SQLiteDatabase mDatabase;
private long fetchPlacesCount() {
String sql = "SELECT COUNT(*) FROM " + DB_TABLE_PLACES;
SQLiteStatement statement = mDatabase.compileStatement(sql);
long count = statement.simpleQueryForLong();
return count;
}
Thanks for sharing
Thank you for posting this. Nice and clean – makes up for a lack of a getSize() method in the SQLiteDatabase class!
Thanks! That exactly what i need
Thanks a lot