【问题标题】:How to retrieve data from SQLite on Android如何在 Android 上从 SQLite 检索数据
【发布时间】:2019-03-20 14:48:12
【问题描述】:

我正在开发一个使用 Ionic 1 和 AngularJS 的项目。我已经成功地将数据存储在 SQLite 中。在 Ionic 的模拟器上(使用ionic serve --lab),数据显示(console.log())如下:

SQLResultSetRowList {0: {…}, length: 1}
0: { // data }
length: 1

所以我可以通过访问结果数组中的对象轻松获取数据。但是,在真实的移动设备上(我在Android上测试),数据是这样显示的。

问题就在这里。我想访问Closure 中的Closure 中的rows,即item: function 中的item: function,我真的不知道它是如何生成的(我的意思是所有这些),因为我唯一的结果是想要的就像我在模拟器中一样。

这就是我插入数据的方式。

$cordovaSQLite.execute(db, "INSERT OR REPLACE INTO token (token) VALUES (?)", [myData]).then(function (res) {
                callback();
            }, function (error) {
                ErrorHandler.handle(error);
            });

这就是我查询数据的方式。

$cordovaSQLite.execute(db, "SELECT * FROM token").then(function (res) {
                console.log(res);
            }, function (error) {
                ErrorHandler.handle(error);
            });

谁有办法解决这个问题?

任何方式都可以接受。

【问题讨论】:

  • 这里有一些有用的答案stackoverflow.com/questions/44876568/…
  • @Thamidunaveen 您提到的链接中的代码是用 Java 编写的。在这种情况下,我不知道那里的哪些信息对我有用。还是谢谢。

标签: android angularjs sqlite ionic-framework


【解决方案1】:

好的。我自己从this找到了解决这个问题的方法。

我需要这样使用它。

if (res.rows.length > 0){
                    if (window.cordova) {
                        // Mobile Device
                        console.log(JSON.parse(res.rows.item(0)));
                    } else {
                        // Web
                        console.log(JSON.parse(res.rows[0]));
                    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-02-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-21
    • 2016-01-28
    • 2018-04-18
    • 2011-09-09
    相关资源
    最近更新 更多