这部分代码效果很好。但是,有机会选择五个搜索选项中的三个。考虑到这一点,我想将UITextField
用于WHERE。例如,替换“Chain =?”替换为“search.text =?”。我熟悉“WHERE Chain = \”%@ \“”,_ somthing.text“但无法解决如何用UITextField
替换硬编码列标题。
任何人都可以帮忙吗?
NSString *querySQL = [NSString stringWithFormat:@"SELECT FullName FROM storeDetails WHERE (Chain = ? AND Format = ? AND RegionCode = ?)"];
const char *query_stmt = [querySQL UTF8String];
if (sqlite3_prepare_v2(detailspapav2, query_stmt, -1, &statement, NULL) == SQLITE_OK)
{
if (sqlite3_bind_text(statement, 1, [_choiceText1.text UTF8String], -1, NULL) != SQLITE_OK) {
NSLog(@"Bind 1 failed");
}
if (sqlite3_bind_text(statement, 2, [_choiceText2.text UTF8String], -1, NULL) != SQLITE_OK) {
NSLog(@"Bind 2 failed");
}
if (sqlite3_bind_text(statement, 3, [_choiceText3.text UTF8String], -1, NULL) != SQLITE_OK) {
NSLog(@"Bind 3 failed");
}
}
答案 0 :(得分:0)
如果您希望列名称为动态,请将querySQL
行更改为某行:
NSString *querySQL = [NSString stringWithFormat:@"SELECT FullName FROM storeDetails WHERE (%@ = ? AND Format = ? AND RegionCode = ?)", search.text];
然而,这很危险。如果search.text
包含的值与FullName
表中列的名称不完全匹配,则查询将失败。