Android 애플리케이션에서 데이터베이스를 업데이트하려고합니다. 버전 번호를 업데이트하면 onUpgrade가 호출되지만 버전 번호가 증가하지 않으므로 데이터베이스에 액세스 할 때마다 onUpgrade가 호출됩니다. 여기 내 코드는 다음과 같습니다 이런 일이 왜onUpgrade 데이터베이스 안드로이드 버전 번호가 증가하지 않습니다
private final static int DB_VERSION = 8;
public DataBaseHelper(Context context) {
super(context, DB_NAME, null, DB_VERSION);
this.myContext = context;
}
@Override
public void onCreate(SQLiteDatabase db) {
Log.d(TAG, "in onCreate");
try {
copyDataBase();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
Log.d(TAG, "in onUpgrade. Old is: " + oldVersion + " New is: " + newVersion);
myContext.deleteDatabase(DB_NAME);
Log.d(TAG, "the version is " + db.getVersion());
db.setVersion(newVersion);
Log.d(TAG, "the version is " + db.getVersion());
onCreate(db);
}
누구나 알아?
아마도이 링크가 도움이 될 수 있습니다. http://stackoverflow.com/questions/7173896/onupgrade-database-oldversion-newversion –
나는이 링크를 이미 보았습니다 ... 나는 아직도 그것을 이해할 수 없습니다. 데이터베이스 버전 번호가 정적 인 경우에도 버전 번호는 onUpgrade()에서 업그레이드되지 않습니다. OnUpgrade가 호출되었지만 나중에 버전 번호가 업데이트되지 않습니다. – coder
onUpgrade가 호출 될 때 oldVersion 및 newVersion의 값은 무엇입니까? –