Android 在Ionic2 v3.4中读取SQLite SELECT查询的结果

Android 在Ionic2 v3.4中读取SQLite SELECT查询的结果,android,sqlite,typescript,ionic2,Android,Sqlite,Typescript,Ionic2,因此,我正在使用最新版本的Ionic2(v3.4),并试图让ionic原生SQLite正常工作。我已经能够创建数据库文件并在其中放置一个表,如下所示: this.sqlite.create({ name: "data.db", location: "default" }) .then((db:SQLiteObject) => { db.executeSql(tableQuery, {}) .then(() => console.log("success")) .c

因此,我正在使用最新版本的Ionic2(v3.4),并试图让ionic原生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}
,就是这样。如何访问查询结果?

让您的表中有三列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);
           }
          });
db.executeSql('SELECT*FROM student,其中id='+1,{})
。然后(结果=>{
对于(var i=0;i
您好,我这里也有同样的问题,它工作了吗?