【问题标题】:Return rows COUNT in Ionic 4在 Ionic 4 中返回行 COUNT
【发布时间】:2019-08-18 17:16:59
【问题描述】:

我正在使用 Ionic 应用程序。我有 SQLITE 数据库。在数据库中,我有一个名为“words”的表。现在我想得到这张表中有多少行。我正在使用我认为正确的 COUNT(*) SQL 命令,因为它非常简单,但是在将数字获取到我的 words.page.ts 文件时遇到问题,函数 getWordsCount() 不起作用,它返回 [object承诺]。

getWordsCount(){
  let count;
  count = this.database.executeSql("select count(*) from words", []);
  return count;
}

实际结果:[object Promise]

预期结果:任意数字(此时为 4)

【问题讨论】:

  • 使用asyncawait方法

标签: sql angular ionic-framework


【解决方案1】:

database.executeSql 方法是一个 Promise。你必须等到 promise 得到解决才能得到结果。

async getWordsCount(){
  let count;
  count = await this.database.executeSql("select count(*) from words", []);
  return count;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-10-14
    • 2019-10-31
    • 2014-07-23
    • 1970-01-01
    • 2021-09-14
    • 2016-10-19
    • 2019-02-09
    • 1970-01-01
    相关资源
    最近更新 更多