I am using sqlite in cordova environment for iPad. While querying a select statement with single input, I do something like this
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.
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?
I couldn't find any documentations for using sqlite with JS. 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);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.