嗯,我有一个数据库,它有很多表。但一般表是空的。 我想检查数据库表是否为空。 如果表是空的,程序会填充它。
public static long queryNumEntries (SQLiteDatabase db, String table)
我会使用它,但它需要 API 11。
最佳答案
您可以执行 select count(*) from table
并检查是否 count> 0
然后离开 else 填充它。
喜欢
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
关于android - Sqlite 检查表是否为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22630307/