2013-10-07 98 views
0

我的我的應用程序的SD卡上的SQlite表。現在,我必須升級我的數據庫。但是,onUpgrade之後,SQLiteOpenHelper的onCreate永遠不會被調用。Android:無法升級從SD卡的SQLite數據庫

這裏是我的代碼:

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"); 
} 

我沒有得到爲什麼,它不是升級到新版本。

回答

1

在onUpgrade中,您必須完成重新創建數據庫的所有工作。 onCreate()在onUpgrade之後不會被調用。

+0

謝謝,你救了我:) – Nitish