/**
*检查某表是否存在
* @param tableName 表名
* @return true:存在 false:不存在
*/
public boolean tabIsExist(String tabName){
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 = mUDB.rawQuery(sql, null);
if(cursor.moveToNext()){
int count = cursor.getInt(0);
if(count>0){
result = true;
}
}
} catch (Exception e) {
}
return result;
}
/**
*检查表中某列是否存在
* @param db
* @param tableName 表名
* @param columnName 列名
* @return true:存在 false:不存在
*/
private boolean checkColumnExists2(SQLiteDatabase db, String tableName , String columnName) {
boolean result = false ;
Cursor cursor = null ;
try{
cursor = db.rawQuery( "select * from sqlite_master where name = ? and sql like ?"
, new String[]{tableName , "%" + columnName + "%"} );
result = null != cursor && cursor.moveToFirst() ;
}catch (Exception e){
Log.e("","checkColumnExists2..." + e.getMessage()) ;
}finally{
if(null != cursor && !cursor.isClosed()){
cursor.close() ;
}
}
return result ;
}
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有