简体   繁体   中英

Ionic 3 - SQLite database was deleted when uninstall App

I have an application development with ionic 3, everything works fine, but when you uninstall and install the application, the database is deleted and a new database is created. My code is:

export class DatabaseServiceProvider {

    private database: SQLiteObject;
    private dbReady = new BehaviorSubject<boolean>(false);
    private formatDate: string = "%d/%m/%Y";
    private formatHours: number = 24;

    constructor(
      private platform: Platform, 
      private sqlite: SQLite,
      private storage: Storage,

    ){
        this.platform.ready().then(()=>{
              this.sqlite.create({
                name:'flb01.db',
                location: 'default'
              }).then((db:SQLiteObject)=>{
                  this.database = db;
                  this.createTables().then(()=>{
                    this.dbReady.next(true);         
                  })
              })
        });
    }


private createTables(){
  return this.database.executeSql(`
    CREATE TABLE IF NOT EXISTS productos (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    nombre TEXT,
    codbar TEXT,
    departamento TEXT,
    empresa TEXT,
    presenta TEXT,
    detalle TEXT,
    presentaold TEXT,
    detalleold TEXT
    );
  `,[])
  .catch((err)=>console.log("Error detectado creando tablas"));
}

}

I am not quite sure of the question, but SQLite databases will be deleted and recreated upon uninstall and reinstall. The reason is because this is local storage on the device. When you remove the application you remove (most) all data with it. If you want a database that doesn't change after uninstall and reinstall, you are going to have to incorporate a cloud based SQL or a data server that requires internet, as far as I am aware.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM