Hi,
I’m not able to get the id of a row using SQLite.
When I try to retrieve the id I get “undefined”. However if I put an ID with a given and valid value of a row on my delete statement it works.
Here is my code :
in Test.html
<ion-list>
<ion-item-sliding *ngFor="let u of user">
<ion-item>
{{u.firstname}} {{u.lastname}} {{u.id}}
</ion-item>
<ion-item-options>
<button ion-button icon-only (click)="delete(u)" danger>
<ion-icon name="trash"></ion-icon>
</button>
</ion-item-options>
</ion-item-sliding>
</ion-list>
In Test.js
public delete(u) {
console.log(u);
console.log(u.firstname);
console.log(u.id); //Return undefined
var query = "DELETE FROM user WHERE `id` = ?";
var curr_id = u.id;
this.database.create({name: "data.db", location: "default"}).then((db: SQLiteObject) => {
db.executeSql(query, [u.id]).then((data) => {
console.log("DELETED: " + JSON.stringify(data));
}, (error) => {
console.log("ERROR: " + JSON.stringify(error.err));
});
});
}
How I create my db :
let db = new SQLite();
db.create({
name: "data.db",
location: "default"
}).then((db: SQLiteObject) => {
db.executeSql("CREATE TABLE IF NOT EXISTS user (id INTEGER PRIMARY KEY AUTOINCREMENT, firstname TEXT, lastname TEXT)", {}).then((data) => {
console.log("TABLE CREATED: ", data);
}, (error) => {
console.error("Unable to execute sql", error);
})
}, (error) => {
console.error("Unable to open database", error);
});
Thanks for helping me !
Ja