????Android???SQLite?????????????????????汾?????????????????????????
??????????v1.0
???????v1.0??????v1.0?汾??????account??????????SQLiteOpenHelper??onCreate??????onUpgrade??
????1??v1.0(?????v1.0)
???????????v2.0
??????2????????????
????1??v1.0   -->  v2.0              ????onCreate????onUpgrade
????2??v2.0(?????v2.0)          ??onCreate??????onUpgrade
????v1.0?汾??????account???????汾??????v2.0???????v2.0???????????????member???????????????????2?????????????????v1.0??????v2.0?????????????SQLiteOpenHelper??onCreate???????????onUpgrade????????onUpgrade???member???????????onCreate?????????????????????????onCreate???????????????????????а?????????????????v2.0?????????SQLiteOpenHelper??onCreate??????onUpgrade?????????onCreate???member????????????????????????????????汾???
???????????v3.0
????????v3.0?????????news??????????????????
????1??v1.0   -->  v3.0              ????onCreate????onUpgrade
????2??v2.0   -->  v3.0              ????onCreate????onUpgrade
????3??v3.0(?????v3.0)          ??onCreate??????onUpgrade
????????????????????????д??????????????汾????DATABASE_VERSION???
???????????£????????onCreateд??onUpgradeд????????????????°??app????????????????????????????????
????1??v1.0     DATABASE_VERSION=1000    onCreate      --???--  account
????2??v2.0     DATABASE_VERSION=1001    onCreate      --???--  account  ??v1.0??????  onUpgrade??DATABASE_VERSION>1000??
????onUpgrade   --???--  member
????3??v3.0     DATABASE_VERSION=1002    onCreate      --???--  account  ??v1.0??????  onUpgrade??DATABASE_VERSION>1001??
????onUpgrade   --???--  member ??v2.0??????
????onUpgrade   --???--  news
?????????????????????????汾?????onCreate???????汾????????onUpgrade????????onCreate???onUpgrade?????ж???????onUpgrade??????ж?????????????????汾????????DATABASE_VERSION???浱????????汾??????????????汾???????????????汾?????????onUpgrade????????????????????汾???oldVersion??????????????汾???newVersion?????????????DATABASE_VERSION?????????????????汾???????????
??????????????????????
??????1????V1.0  : DATABASE_VERSION = 1000 ??????favorite??
public class DBHelper extends SQLiteOpenHelper {
private static final String DATABASE_NAME = "mall.db";
private static final int DATABASE_VERSION = 1000;
private static DBHelper instance = null;
public DBHelper(Context context) {
super(context?? DATABASE_NAME?? null?? DATABASE_VERSION);
}
public synchronized static DBHelper getInstance(Context context) {
if (instance == null) {
instance = new DBHelper(context);
}
return instance;
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(SQL.CREATE_TABLE_FAVORITE);
// ??????????汾????????????????????
// ??????FIRST_DATABASE_VERSION??????????????????汾??С
final int FIRST_DATABASE_VERSION = 1000;
onUpgrade(db?? FIRST_DATABASE_VERSION?? DATABASE_VERSION);
}
@Override
public void onUpgrade(SQLiteDatabase db?? int oldVersion?? int newVersion) {
// ???for????汾?????????
for (int i = oldVersion; i < newVersion; i++) {
switch (i) {
default:
break;
}
}
}
}