mehmet mehmet - 1 year ago 185
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.

Answer Source

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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download