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.
The DISTINCT clause allows you to remove the duplicate rows in the result set. In this syntax: First, the DISTINCT clause must appear immediately after the SELECT keyword. Second, you place a column or a list of columns after the DISTINCT keyword.
SQLite IS NOT NULL operator.
Show activity on this post. import MySQLdb db = MySQLdb. connect(passwd="moonpie", db="thangs") results = db. query("""SELECT * from mytable limit 1""") if not results: print "This table is empty!"
you can execute select count(*) from table
and check if count> 0
then leave else populate it.
like
SQLiteDatabase db = table.getWritableDatabase(); String count = "SELECT count(*) FROM table"; Cursor mcursor = db.rawQuery(count, null); mcursor.moveToFirst(); int icount = mcursor.getInt(0); if(icount>0) //leave else //populate table
Do a SELECT COUNT
:
boolean empty = true Cursor cur = db.rawQuery("SELECT COUNT(*) FROM YOURTABLE", null); if (cur != null && cur.moveToFirst()) { empty = (cur.getInt (0) == 0); } cur.close(); return empty;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With