Currently, I'm working with the latest version of Ionic2 (v3.4) and attempting to utilize the ionic native SQLite functionality. Successfully, I've managed to create a database file and insert a table into it as shown below:
this.sqlite.create({
name: "data.db",
location: "default"
})
.then((db:SQLiteObject) => {
db.executeSql(tableQuery, {})
.then(() => console.log("success"))
.catch(() => console.log("fail"));
})
The insertion process is also functioning properly. However, when trying to retrieve the result of a selection query:
this.sqlite.create({
name: "data.db",
location: "default"
})
.then((db:SQLiteObject) => {
db.executeSql("SELECT * FROM savedCoupons where itemId=" + itemId, {})
.then((db) => {console.log(JSON.stringify(db))})
.catch(() => console.log("***ERROR WITH SELECT***"));
})
.catch(() => console.log("ERROR: FAILED TO CREATE/OPEN DATABASE."));
Confusion arises due to inadequate documentation. Despite using JSON.stringify()
to confirm the query's execution, the returned value is limited to
{"rows":{"length":1}, "rowsAffected":0}
. How can I effectively access the query results?