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

时间:2014-05-24 09:32:53   收藏:0   阅读:703
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

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

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!