ios - Arbitrary SQL with NSArray as Statement Argument -


i use sqlite.swift , want create sql statement this:

"select * user id in({userdtoids})" 

i did

let arr:[string] = // nsarray of strings let stmt:statement = db.prepare("select * \(tablename) id in(?)") 

but stmt.run() not allow [string] argument.

how can use nsarray argument sql statement in sqlite.swift?

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

table.filter(contains(ids, id))  // above assumes boilerplate precedes it: let table = db["tablename"] let id = expression<int64>("id") let ids: [int64] = [1, 2, 3, 4, 5] // e.g. 

if you're using raw sqlite3 api, not support arrays, you'll need format yourself:

let template = join(", ", [string](count: count(ids), repeatedvalue: "?")) let stmt = db.prepare(     "select * \(tablename) id in (\(template))", ids ) 

Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

datatable - Matlab struct computations -