离子executeSql不起作用

Noo*_*oby 6 sqlite mobile ionic-framework

我实际上尝试使用SQLite制作移动应用程序.我试着创建两个表:

constructor(private sqlite:SQLite,public modalCtrl: ModalController,public navCtrl: NavController, private navParam: NavParams, private databaseprovider: DatabaseProvider, private employeesProvider: EmployeeProvider) {
    this.createDetabaseFile();
}

private createDetabaseFile() : void {
    this.sqlite.create({
          name: DATABASE_FILE_NAME,
          location: 'default'
    }).then((dbRes: SQLiteObject) => {
        alert("bdd créée");
        this.db = dbRes;
        this.createTables();
    })
}

private createTables() : void {
    this.db.executeSql('CREATE table IF NOT EXISTS  symbole(id INTEGER NOT NULL ,name TEXT)',{})
        .then(() => {
            alert("table symbole created");
            this.db.executeSql('CREATE table IF NOT EXISTS representationPhoto(name VARCHAR(32))',{})
                .then(() => {
                    alert("table representationPhoto created");
                })
            .catch(e => alert("erreur creation table"));
        })
        .catch(e => alert("erreur creation table"));
}
Run Code Online (Sandbox Code Playgroud)

并且db.executeSql()似乎不起作用,确实,alert("table symbole created");不会出现,但是alert("bdd créée")出现,并且程序不会触发捕获.

你有个主意吗?

ps:抱歉我的英语不好

小智 0

请尝试在 createDetabaseFile 函数上方声明 db 变量,在我看来这是问题,因为您正在使用 this.db 而不在类范围中声明它。

尝试这样做:

public db: any; // above createDetabaseFile function
Run Code Online (Sandbox Code Playgroud)