首页 > 移动平台 > 详细

android在sqlite数据库的SQLiteOpenHelper中的onUpgrade里判断表是否存在

时间:2014-05-24 09:32:53      阅读:702      评论:0      收藏:0      [点我收藏+]
bubuko.com,布布扣
private boolean tabbleIsExist(String tableName, SQLiteDatabase db) {
            LogUtils.d("DatabaseHelper", "checking tabbleIsExist " + tableName);
            boolean result = false;
            if (tableName == null) {
                return false;
            }
            Cursor cursor = null;
            try {
                String sql = "select count(*) as c from sqlite_master where type =‘table‘ and name =‘"
                        + tableName.trim() + "‘ ";
                cursor = db.rawQuery(sql, null);
                if (cursor.moveToNext()) {
                    int count = cursor.getInt(0);
                    if (count > 0) {
                        result = true;
                    }
                }

            } catch (Exception e) {
                LogUtils.e("DatabaseHelper", "error in tabbleIsExist:" + e.toString());
            }
            LogUtils.d("DatabaseHelper", "checking tabbleIsExist "
                    + tableName + " " + result);
            return result;
        }
bubuko.com,布布扣

 

android在sqlite数据库的SQLiteOpenHelper中的onUpgrade里判断表是否存在,布布扣,bubuko.com

android在sqlite数据库的SQLiteOpenHelper中的onUpgrade里判断表是否存在

原文:http://www.cnblogs.com/gccBlog/p/3748743.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!