mehmet mehmet - 8 months ago 87
Android Question

Sqlite Check if Table is Empty

Well, I have a databse and it has lots of table. but generally tables are empty.
I want check if a database table is empty.
IF table is empty, program will fill it.

public static long queryNumEntries (SQLiteDatabase db, String table)

I will use it but it requre API 11.


you can execute select count(*) from table and check if count> 0 then leave else populate it.


 SQLiteDatabase db = table.getWritableDatabase();
String count = "SELECT count(*) FROM table";
Cursor mcursor = db.rawQuery(count, null);
int icount = mcursor.getInt(0);
//populate table