【发布时间】:2016-03-25 13:52:08
【问题描述】:
在JavascriptSQLite 中,有没有更好的方法可以执行带有WHERE IN 子句的SELECT 语句?我们以下面的查询为例:
var ids = [1, 5, 10];
function getBranches (ids) {
db.transaction(function(tx) {
tx.executeSql('SELECT * FROM Branch WHERE id in ?', [ids], function(tx,results){
// process results
});
});
}
我知道我们总是可以以SQL 识别它的方式为 id 格式化 WHERE IN 子句,如下所示。但我想知道是否有一个很好的方法来满足这个要求。
function getBranches (ids) {
db.transaction(function(tx) {
var idClause = ' id in (\"' + ids.join("\",\"") + '\");';
tx.executeSql('SELECT * FROM Branch WHERE ' + idClause, [], function(tx,results){
// process results
});
});
}
【问题讨论】:
标签: javascript sql sqlite