ngCordova - 无法获取SQLite记录

时间:2015-06-17 17:05:20

标签: sqlite cordova ionic-framework ngcordova

我想知道我在这里做错了什么,像大多数cordova插件一样调试它......

我只是想存储一些字符串......(我只需要在一个控制器中使用它)

var db = $cordovaSQLite.openDB({ name: "videos" });
$cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS videos (id integer primary key, video mediumtext)");

// getting some data from the server, nothing special

query = "INSERT INTO videos (id, video) VALUES (?)";
$cordovaSQLite.execute(db, query, [response.Data.media]).then(function(result) {
  console.log(result);
  var message = "INSERT ID -> " + result.insertId;
  console.log(message);
}, function (err) {
  console.error(err);
  //alert(err);
});

我得到了插入的ID,所以它必须保存一些东西......但是当我尝试使用函数加载它时

var query = "SELECT * FROM videos where id = 1";
$cordovaSQLite.execute(db, query).then(function(result) {
  console.log(result);
});

我一无所获。

enter image description here

天体物理学家称之为空地,但我们是开发人员,我们需要处理数据!为什么行中什么都没有? (无论我选择id还是所有内容,它只是向我显示这种没有数据的空对象。)

非常感谢您的帮助!

1 个答案:

答案 0 :(得分:4)

你应该可以像这样循环结果:

var output = [];
for (var i = 0; i < result.rows.length; i++) {
    output.push(result.rows.item(i));
}
console.log(JSON.stringify(output));

然后,当您查看输出时,它将包含带有数据的结果数组。