码迷,mamicode.com
首页 > 移动开发 > 详细

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

时间:2014-05-24 09:32:40      阅读:206      评论:0      收藏:0      [点我收藏+]

标签:android   style   class   blog   c   code   

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里判断表是否存在

标签:android   style   class   blog   c   code   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!