You can build your pattern in Swift, and use a single parameter: let queryString = "select name, phone, street, city, state from phone where name like '?'" let pattern = "%\(name)%" if sqlite3_bind_text(stmt, 1, pattern, -1, SQLITE_TRANSIENT) != SQLITE_OK {do whatever}
For a more detailed explanation of the reasons why you get an error with this LIKE query see this dedicated FAQ: https://github.com/groue/GRDB.swift/blob/master/README.md#sqlite-error-21-wrong-number-of-statement-arguments-with-like-queries Gwendal Roué On Thu, Sep 26, 2019 at 3:26 PM Daniel Odom <djo...@djodom.com> wrote: > I am just now getting around to learning Swift and XCode. I am having a > problem with 'LIKE'. When I do this: > > let queryString = "select name, phone, street, city, state from phone > where name like '%?%'" > > And then this: if sqlite3_bind_text(stmt, 1, name, -1, SQLITE_TRANSIENT) > != SQLITE_OK {do whatever} > > I get an error "column index out of range". The rest of the code is > fine. When I do this: > > let queryString = "select name, phone, street, city, state from phone > where name = ?" > > everything works just fine. What am I missing? > > _______________________________________________ > sqlite-users mailing list > sqlite-users@mailinglists.sqlite.org > http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users > _______________________________________________ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users