android - Sqlite 检查表是否为空

标签 android database sqlite

嗯,我有一个数据库,它有很多表。但一般表是空的。 我想检查数据库表是否为空。 如果表是空的,程序会填充它。

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/

相关文章:

Android TextView 需要 FadingEdge 渐变方向

android - 具有 HDPI/MDPI 分辨率的小屏幕时,字体大小会过大

apache-flex - Flex AIR Sqlite 作为嵌入式数据库

java - MapActivity 中的数据库处理

android - 模拟器 : queryCoreProfileSupport: swap interval not found

android - 如何在 android 的 firebase ui 身份验证中添加 Logo ?

PHPExcel 和文本换行

php - 检查插入或更新表

linux - orientdb 连接无效的密码和用户名

android - 将文本框中的值插入 SQLite 数据库