在手机端程序升级过程中,可能需要增加表或者字段,但又要同时兼容原来的版本,那么就需要判断原来版本有没有新增的表,如果没有就创建,有的话直接添加数据即可。。。 贴出代码,方便以后使用……
public boolean tabIsExist(String tabName, SQLiteDatabase db) {
boolean result = false;
if (tabName == null)
return false;
Cursor cursor = null;
try {
String sql = "select count(*) as c from sqlite_master where type ='table' and name ='"
+ tabName.trim() + "' ";
cursor = db.rawQuery(sql, null);
if (cursor.moveToNext()) {
int count = cursor.getInt(0);
if (count > 0) {
result = true;
}
}
} catch (Exception e) {
// TODO: handle exception
}
return result;
}
本文链接:https://it72.com/2135.htm