Reputation: 833
I wrote a query with arguments in FMDB using ? mark symbol.I want to get details of users who has any of info in the list(hope i can give different info separated by commas in "in" statement in sql). Since my arguments having special symbols, It is throwing error. How to escape there special symbols. I tried different methods but none worked yet
My code is like:
FMResultSet *results = [db executeQuery:@"select details from user where info in(?)",infoList];
while([results next])
{...}
Info is a string combined by different string seperated by commas.For example:
'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'
Thanks in advance
Upvotes: 0
Views: 627
Reputation: 318824
You can't use a single ?
with an in
clause unless you only bind a single value. It doesn't work for a list of values.
Since infoList
is an array of string values, one option is to add a ?
for each value in the list.
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];
Upvotes: 4