6

I'm trying to pass an array parameter to the function executeSql of SQLiteObject in Ionic to make it a value for my SQL query.

For example

var sqlQuery: string = "SELECT * FROM Property WHERE ID IN (?) AND Status = ?"
var ids: number[] = [123, 321, 456];

and I'm trying to pass it here,

var db: SQLiteObject
db.executeSql(sqlQuery, [ids, 0])

So basically I want to insert all the values of ids to the IN operator and 0 for Status. But I think the SQL interprets it differently.

I tried to pass it as a string db.executeSql(sqlQuery, [ids.toString(), 0]) to remove the unnecessary characters and such. But still, it doesn't return anything.

NOTE I know I need it to enclose to a promise or something, but I just sliced it and summarise it to remove the unnecessary codes. Thanks.

1 Answer 1

4

I tried to search all over but still can't find a definite answer. I just invented a workaround for it by doing this method.

var ids: number[] = [123, 321, 456];
var sqlQuery: string = "SELECT * FROM Property WHERE ID IN (" + ids.toString() + ") AND Status = ?";

And pass it to executeSql function

var db: SQLiteObject
db.executeSql(sqlQuery, [0]);

This is just a work around. I'll still wait for a better solution. Thanks!

Sign up to request clarification or add additional context in comments.

Comments

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.