Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing Array parameter to SQLiteObject.executeSql()

I'm trying to pass an array parameter to the function executeSql of SQLiteObject in ionic to make it as 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 summarize it to remove the unnecessary codes. Thanks.

like image 540
Rich Avatar asked Jan 29 '18 09:01

Rich


Video Answer


1 Answers

I tried to search all over but still can't find a definite answer, I just invent a work around 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!

like image 110
Rich Avatar answered Nov 15 '22 04:11

Rich