[英]Pass input to sqlite IN operator (Javascript, Cordova)
I am using sqlite in cordova environment for iPad. 我在用于iPad的cordova环境中使用sqlite。 While querying a select statement with single input, I do something like this 在使用单个输入查询select语句时,我会这样做
tx.executeSql("select * from activityData_table where id=? ;", [outage.outageId], function(tx, res)
But what if I want to select using a IN operator as given below. 但是,如果我想选择使用下面给出的IN运算符,该怎么办呢?
select * from activityData_table where id in (val1,val2,val2)
How will I form the query and pass inputs to it. 我将如何形成查询并将输入传递给它。 Will a array of values suffice or do we need to manually do any concat operations? 一组值是否足够或我们是否需要手动执行任何concat操作?
I couldn't find any documentations for using sqlite with JS. 我找不到任何与JS一起使用sqlite的文档。 If any one could suggest a documentation or a tutorial site for reference will be of great help. 如果任何人可以建议文档或教程网站供参考将是非常有帮助的。
You could get the count of the values and then generate the statement like this (pseudo code): 您可以获取值的计数,然后生成这样的语句(伪代码):
var values = [1,2,3,4];
var count = values.length;
var sql = 'select * from activityData_table where id in (';
for (var i = 0; i < count; i++) {
if(i != (count - 1)) {
sql += '?,';
}
else {
sql += '?)';
}
}
tx.executeSql(sql,values);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.