假设我有一个名为name的搜索框。如果用户在搜索框中输入了“John”,那么我应该检查“Name”字段是否包含值“John”,并选择所有相应的字段值。“John”是NSString类型,可以从searchBar.text获取,并将其作为参数添加到查询中。我尝试过以下结构化的SQL语句,但它从未起作用。
NSString *query = [NSString stringWithFormat:@"select * from Employee where EmployeeName LIKE '%%@%'", searchText.text];
const char *sqlStatement = [query UTF8String];
我也尝试过这个
NSString *query = [NSString stringWithFormat:@"select * from Employee where EmployeeName LIKE %'%@'%", searchText.text];
const char *sqlStatement = [query UTF8String];
什么都没用。
\%
和%%
不是一样的吗?用\%
不会显得更少...百分号吗? - Mike Lentini