所以我使用了最新版本的Ionic2(v3.4),并试图让离子原生SQLite工作。我已经能够创建数据库文件并将表格放入其中:
this.sqlite.create({
name: "data.db",
location: "default"
})
.then((db:SQLiteObject) => {
db.executeSql(tableQuery, {})
.then(() => console.log("success"))
.catch(() => console.log("fail"));
})
插入也有效。但是当我试图得到选择的结果时:
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."));
由于缺乏文件,我迷路了。 JSON.stringify()
正在运行,因此查询似乎有效。它返回{"rows":{"length":1}, "rowsAffected":0}
即可。如何访问查询结果?
答案 0 :(得分:0)
在表格中有三列e.x id,name,lastname。 查询后,您可以访问它:
db.executeSql('SELECT * FROM student WHERE id='+1, {})
.then(result => {
for (var i = 0; i < result.rows.length; i++) {
console.log("---Id---"+result.rows.item(i).id);
console.log("---Name---"+result.rows.item(i).name);
console.log("---Lastname---"+result.rows.item(i).lastname);
}
});