Ionic executeSql doesn't work


#1

Hello,
I actually try to make an mobile app with SQLite. I juste try to create two tables:

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

And db.executeSql() seem not working, indeed, the alert(“table symbole created”); don’t appear, however alert(“bdd créée”) appear, and the program don’t triggered the catch.

Have you an idea?

ps: sorry for my bad english


#2

Please I don’t find the solution…
I think the this.sqlite.create doesn’t work.
I have tried in a other android device, to create a new blank project, to update with npm install, to past the official doc, to past sqlite’s tuto on different websites … but still not work…


#3

Try this …
getdata(){
this.sqlite.create({
name: ‘ionicdb.db’,
location: ‘default’
}).then((db: SQLiteObject) => {
db.executeSql(‘CREATE TABLE IF NOT EXISTS drs_customers(ROWID INTEGER PRIMARY KEY,DCU_CUST_ID NUMBER, DCU_CUST_NAME TEXT, DCU_ADDR1 TEXT)’, {})
.then(res => console.log(‘Executed SQL’))
.catch(e => console.log(e));
})
}