0

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.

1 Answer 1

3

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);
Sign up to request clarification or add additional context in comments.

2 Comments

Yes. I thought about this. But I want the code to be cleaner. Thats why hesitating to use this.
A true case of bikeshedding

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.