我的SD卡上的SQlite表用于我的应用程序。现在,我必须升级我的数据库。但是,在onUpgrade之后,SQLiteOpenHelper的onCreate永远不会被调用。
这是我的代码:
public class DatabaseHandler extends SQLiteOpenHelper {
private static final String DATABASE_NAME = Environment
.getExternalStorageDirectory().getAbsolutePath()
+ "/"
+ Environment.DIRECTORY_DOWNLOADS + "/MyApp.sqlite";
public void onCreate(SQLiteDatabase db) {
Log.e(TAG, "DB onCreate");
// String CREATE_SCHEMA =
db.execSQL("CREATE TABLE Master ("
+ " ID integer PRIMARY KEY NOT NULL ,"
+ " UserName varchar(50) NOT NULL ,"
+ " DriverID int NOT NULL ,"
+ " DriverName varchar(100) NULL ,"
+ " MobilePrint int NOT NULL DEFAULT 0 ,"
+ " LastSyncUTC text NULL ,"
+ " SchemaVersion TEXT NOT NULL ,"
+ " PasswordHash TEXT NULL ," + " SyncMinutes int NOT NULL ,"
+ " LatestAppVersion TEXT NOT NULL" + ");");
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO: handle updates when they are necessary
Log.e(TAG, "DB onUpgrade");
db.execSQL("DROP TABLE IF EXISTS " + "Master");
}
我不明白为什么,它没有升级到新版本。
答案 0 :(得分:1)
在onUpgrade中,您必须完成重新创建数据库的所有工作。在onUpgrade之后不调用onCreate()。