Arbitrary SQL with NSArray as Statement Argument


I use SQLite.swift and want to create an SQL statement like this:

"SELECT * FROM user WHERE id IN({userDtoIds})"

I did

let arr:[String] = // NSArray of Strings
let stmt:Statement = db.prepare("SELECT * FROM \(tableName) WHERE id IN(?)")

But does not allow [String] as argument.

How can I use an NSArray as argument for an SQL Statement in SQLite.swift?

By : zallarak


If you're using the type-safe layer, you can use contains():

table.filter(contains(ids, id))

// the above assumes this boilerplate precedes it:
let table = db["tableName"]
let id = Expression

This video can help you solving your question :)
By: admin