【问题标题】:Ionic 3 - SQLite database was deleted when uninstall AppIonic 3 - 卸载应用程序时删除了 SQLite 数据库
【发布时间】:2019-03-20 07:58:51
【问题描述】:

我有一个使用 ionic 3 的应用程序开发,一切正常,但是当您卸载并安装应用程序时,数据库被删除并创建了一个新数据库。我的代码是:

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

}

【问题讨论】:

    标签: android sqlite cordova ionic3 ionic-native


    【解决方案1】:

    我不太确定这个问题,但 SQLite 数据库将在卸载和重新安装时被删除并重新创建。原因是因为这是设备上的本地存储。当您删除应用程序时,您会删除(大部分)所有数据。如果您想要一个在卸载和重新安装后不会更改的数据库,那么据我所知,您将不得不合并基于云的 SQL 或需要互联网的数据服务器。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-12-02
      • 1970-01-01
      • 2018-09-15
      • 1970-01-01
      • 2021-07-09
      • 1970-01-01
      • 2020-06-22
      • 1970-01-01
      相关资源
      最近更新 更多