views:

185

answers:

1

hi all,

I have problems running a dynamic LIKE statement in my project: this query works like a charm and returns all items with a 't' in there name:

const char *sql = "select * from bbc_ipad_v1_node where name LIKE '%%t%%'";

When I try to do this dynamically I do not get erros, but just an empty result. It seems that the value is nill. I try to bind a string value 's' which outputs a 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 should I bind this value instead of using:

const char *sql = "select * from bbc_ipad_v1_node where name LIKE '%%?%%'";

Thomas

+1  A: 

hi all!

Just found a great explanation at http://www.innerexception.com/2008/10/using-like-statement-in-sqlite-3-from.html

I changed 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); 
Thomas Joos