转义 FMDB iOS 查询中的特殊字符
Escape special characters in FMDB iOS query
我在 FMDB 中使用 ? mark symbol.I 想要获得拥有列表中任何信息的用户的详细信息(希望我可以在 sql 的 "in" 语句中提供不同的信息,用逗号分隔)。由于我的参数具有特殊符号,因此会引发错误。如何逃脱那里的特殊符号。我尝试了不同的方法,但 none 仍然有效
我的代码是这样的:
FMResultSet *results = [db executeQuery:@"select details from user where info in(?)",infoList];
while([results next])
{...}
Info 是由 commas.For 分隔的不同字符串组合而成的字符串 示例:
'C-note','Cuban missile crisis, the','cubbyhole','I Love Lucy','I'm a Celebrity ... Get me Out of Here!','Iacocca, Lee','-iana','Ivy League, the'
提前致谢
您不能将单个 ?
与 in
子句一起使用,除非您只绑定一个值。它不适用于值列表。
由于 infoList
是一个字符串值数组,一个选项是为列表中的每个值添加一个 ?
。
NSMutableString *query = [NSMutableString stringWithString:@"select details from user where info in ("];
for (NSInteger i = 0; i < infoList.count; i++) {
if (i) {
[query appendString:@","];
}
[query appendString:@"?"];
}
[query appendString:@")"];
FMResultSet *results = [db executeQuery:query withArgumentsInArray:infoList];
我在 FMDB 中使用 ? mark symbol.I 想要获得拥有列表中任何信息的用户的详细信息(希望我可以在 sql 的 "in" 语句中提供不同的信息,用逗号分隔)。由于我的参数具有特殊符号,因此会引发错误。如何逃脱那里的特殊符号。我尝试了不同的方法,但 none 仍然有效
我的代码是这样的:
FMResultSet *results = [db executeQuery:@"select details from user where info in(?)",infoList];
while([results next])
{...}
Info 是由 commas.For 分隔的不同字符串组合而成的字符串 示例:
'C-note','Cuban missile crisis, the','cubbyhole','I Love Lucy','I'm a Celebrity ... Get me Out of Here!','Iacocca, Lee','-iana','Ivy League, the'
提前致谢
您不能将单个 ?
与 in
子句一起使用,除非您只绑定一个值。它不适用于值列表。
由于 infoList
是一个字符串值数组,一个选项是为列表中的每个值添加一个 ?
。
NSMutableString *query = [NSMutableString stringWithString:@"select details from user where info in ("];
for (NSInteger i = 0; i < infoList.count; i++) {
if (i) {
[query appendString:@","];
}
[query appendString:@"?"];
}
[query appendString:@")"];
FMResultSet *results = [db executeQuery:query withArgumentsInArray:infoList];