How to use SQLITE3 LIKE statement
I'm having trouble running a dynamic LIKE statement in my project: this query works like a charm and returns all items with "t" in their name:
const char *sql = "select * from bbc_ipad_v1_node where name LIKE '%%t%%'";
When I try to do it dynamically, I get no errors, just an empty result. The value seems to be null. I am trying to bind the string value 's' that outputs the correct value
NSLog(@"bbc_ : search menu items from db based on: %@",s);
const char *sql = "select * from bbc_ipad_v1_node where name LIKE '%%?%%'";
sqlite3_stmt *statement;
if (sqlite3_prepare_v2(database, sql, -1, &statement, NULL) == SQLITE_OK) {
sqlite3_bind_text(statement, 1, [s UTF8String],-1,SQLITE_TRANSIENT);
How do I bind this value instead of using:
const char *sql = "select * from bbc_ipad_v1_node where name LIKE '%%?%%'";
+2
a source to share
2 answers
Just found a great explanation at http://www.innerexception.com/2008/10/using-like-statement-in-sqlite-3-from.html
I changed the following lines:
const char *sql = "select * from bbc_ipad_v1_node where name LIKE ?001";
and
NSString *searchInput = [NSString stringWithFormat:@"%@%%", s];
sqlite3_bind_text(statement, 1, [searchInput UTF8String],-1,SQLITE_TRANSIENT);
+4
a source to share