If I update my Android app will the data in the Sqlite database be deleted? [duplicate]

-1

** Hello, I have an application in the App Store and I want to update it. If I update it will the data in the database be deleted? For example, people who have registered will lose their account?

Someone enlighten me please **

    
asked by Berzokovyx 29.08.2017 в 18:47
source

1 answer

-1

If you update the app ( versionCode ) the data is not lost. If you modify / update the SQLite database if the data can be lost. I think the most common is to add a column to a BD, therefore you have to update the code: in DATABASE_VERSION change to a larger number, in onCreate you add the new column, and if you do not want to lose data already saved in the database, use the ALTER TABLE in the onUpgrade method. Example:

     @Override  public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
  if (newVersion > oldVersion) {
      db.execSQL("ALTER TABLE tutabla ADD COLUMN tu_nueva_columna INTEGER"); 
      //db.execSQL("ALTER TABLE tutabla ADD COLUMN tu_nueva_columna");        // sin mencionar el tipo  
  } 
}
    
answered by 30.08.2017 / 01:16
source