安卓 sqlite 数据库版本更新

       try {
            if (oldVersion == 1 && newVersion >= 2) {
                //从版本1到版本2时,增加了一个字段 desc
                String sql = "ALTER TABLE patrol_assets ADD duration long";
                db.execSQL(sql);
            }

            if (oldVersion <= 2 && newVersion >= 3) {
                //从版本1到版本2时,增加了一个字段 desc
                String sql = "ALTER TABLE patrol_task ADD unread int";
                db.execSQL(sql);
            }

            if (oldVersion <= 3 && newVersion >= 4) {

                String sql =  "CREATE TABLE IF NOT EXISTS device_data(" +
                        "id INTEGER PRIMARY KEY AUTOINCREMENT" +
                        ",cur_uid int,sn varchar(100)" +
                        ",name varchar(100)" +
                        ",state int" +
                        ",device_type int" +
                        ",create_time varchar(100))";
                db.execSQL(sql);

                String sql2 = "ALTER TABLE patrol_assets ADD device_sn varchar(100)";
                db.execSQL(sql2);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

 

你可能感兴趣的:(安卓 sqlite 数据库版本更新)