Sqlite.房子的查询
Sqlite.jsm queries
我正在尝试使用sqlite。jsm而不是mozStorage。这里是我的原始代码文件。
var sql = "UPDATE row SET color=?1 WHERE id=?2";
var statement = connection.createAsyncStatement(sql);
statement.bindInt32Parameter(0, row.color);
statement.bindInt32Parameter(2, row.id);
statement.executeAsync();
新代码:
Components.utils.import("resource://gre/modules/Sqlite.jsm");
Components.utils.import("resource://gre/modules/Task.jsm");
Task.spawn(function() {
var db;
try {
// Open a database
db = yield Sqlite.openConnection({ path: "file.sqlite" });
var sql = "UPDATE row SET color=?1 WHERE id=?2";
var dataToInsert = [
["color", row.color],
["id", row.id],
for (var data of dataToInsert) {
yield db.execute(sql, data);
}
} catch (ex) {
// **Here i get : Error(s) encountered during statement execution.**
} finally {
if (db) {
yield db.close();
}
}
});
那么如何在UPDATE查询中使用sqlite传递参数。房子吗?提前感谢
对于提问的人来说可能有点晚了,但仍然可能有用。
Sqlite。JSM鼓励使用带有命名参数和对象的查询作为参数存储,所以正确的代码应该是这样的:
Components.utils.import("resource://gre/modules/Sqlite.jsm");
Components.utils.import("resource://gre/modules/Task.jsm");
return Task.spawn(function*() {
var db;
try {
// Open a database
db = yield Sqlite.openConnection({path: "file.sqlite"});
var sql = "UPDATE row SET color = :color WHERE id = :id";
var params = {
'color': row.color,
'id': row.id
};
return db.execute(sql, params);
} catch (ex) {
// Exception handling
} finally {
if (db) {
yield db.close();
}
}
});
相关文章:
- 内部分区字体大小获胜'调整浏览器窗口大小时不会随媒体查询而更改
- j查询utc offSets的时差
- 如何有效地将游戏数据存储在URL查询字符串中
- 如何处理node.js节点mongodb中的连接和查询队列
- 如何从 HTML 查询中删除项目
- 从查询字符串参数推断出正确的数据类型
- 将curl查询转换为jQuery.ajax()
- 触发媒体查询断点时刷新页面
- 使用DynamoDB查询返回
- 当查询不在displayField中时,引导Ajax Typeahead不显示结果
- 如何将PHP get查询转换为Meteor's HTTP.get()
- AngularJS:获取链接中没有哈希的查询字符串值
- 捕获初始RedQueryBuilder查询中的SQL问题
- AngularJS,如何更改查询字符串
- 具有大型几何图形的基于沙发的空间查询
- 在php中提交数据时,如果某些值为null,而某些值为非null,如何进行查询
- o数据扩展查询在SystemUserRolesSet上不起作用
- Xpath运行缓慢的查询
- Solr查询以按日期月份获取数据&年
- Sqlite.房子的查询