【问题标题】:can't get the rows item only get the count of rows ionic 3 sqlite无法获取行项目仅获取离子 3 sqlite 的行数
【发布时间】:2018-02-23 02:08:23
【问题描述】:

我正在学习 ionic 3,我遇到了一个步骤,我必须在加载应用程序时从我的 sqlite 数据库中检查并检查用户表是否有任何条目,如果是,则从表中获取用户名,但是当我执行查询然后我只得到我查询的行的长度:

this.db.executeSql('Select * FROM users', {})
.then(data => console.log(data))
.catch(e => console.log(e));

我在控制台中得到的输出是:

{rows: {…}, rowsAffected: 0, insertId: undefined}

展开后控制台响应结果为

insertId:undefined
rows:
    item:ƒ (i)
    length:1
  __proto__:Object
  rowsAffected:0
__proto__:Object

如果有人知道发生这种情况的原因,请帮助我。您的回答对我来说非常有价值。谢谢

【问题讨论】:

    标签: sqlite ionic3


    【解决方案1】:

    我认为我应该使用对事务的调用。

    Read data from the database

    示例:

    this.db.transaction((tx: any) => {
        tx.executeSql('Select * FROM users', {},
            (tx: any, res: any) => {
                for (var x = 0; x < res.rows.length; x++) {
                    console.log("row: " + res.rows.item(x));
                }
            }, (tx: any, err: any) => {
                //reject({ tx: tx, err: err })
            });
    
    }, (err: any) => {
        //reject({ tx: tx, err: err })
    });
    

    【讨论】:

    • 感谢您的回复先生,我尝试了您的方法,但我无法获取行数.. 但只能获取行数
    • 您的表格似乎缺少数据。
    • 数据将在 res.rows.item (x) 上可用。你会得到 res.rows.item(x).yourfield.
    • 非常感谢先生,我明白了你的意思,并从我的 sqlite 数据库中获取数据。非常感谢,非常感谢。先生,我还有一个问题可以直接从我的安卓设备上读取 sqlite 吗?
    • 我相信您将不得不为这个问题创建一个新主题。
    猜你喜欢
    • 2019-09-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-05
    • 2017-06-30
    • 1970-01-01
    相关资源
    最近更新 更多