ios - 转义 FMDB iOS 查询中的特殊字符

标签 ios sql sqlite special-characters fmdb

我在 FMDB 中使用 ?标记符号。我想获取在列表中具有任何信息的用户的详细信息(希望我可以在 sql 的“in”语句中提供以逗号分隔的不同信息)。由于我的参数具有特殊符号,因此会引发错误。如何逃脱那里的特殊符号。我尝试了不同的方法,但都没有奏效

我的代码是这样的:

FMResultSet *results = [db executeQuery:@"select details from user where info in(?)",infoList];
while([results next])
    {...}

Info 是由逗号分隔的不同字符串组合而成的字符串。例如:

'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 子句一起使用,除非您只绑定(bind)一个值。它不适用于值列表。

由于 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];

关于ios - 转义 FMDB iOS 查询中的特殊字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33153274/

相关文章:

ios - 我如何测量建筑物内的短距离

ios - code sign wants sign using key - 不允许或总是允许但拒绝工作

mysql - 将我的 SQL 减少了 40%,但运行速度却慢了 60 倍?

sql - hive 中的GROUPING()?

以下场景的 MYSQL 查询

iOS-从另一个类中的completionHandler block 访问 View 相关类

ios - 使用 NSUndoManager 强制保存 NSManagedObject

android - 将 JSON 存储在 sqlite 字段中?

android - 如何查询两个日期时间列之间的行?

c++ - 如何将数据从字符串C++插入到sqlite表?