Reputation: 307
I need to do a Select statement using the IN clause with an NSArray in Objective-C. Something like this
NSArray *countries = [NSArray arrayWithObjects:@"USA", @"Argentina", @"England", nil];
if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) {
const char *sqlStatement =
[[NSString stringWithFormat:@"select currencies from money where country IN countries] UTF8String];
....
where IN countries is the NSArray with the string values. Is this posible?
Upvotes: 1
Views: 938
Reputation: 3905
Change the query string to :
const char *sqlStatement =
[NSString stringWithFormat:@"select currencies from money where country IN ('%@')",[countries componentsJoinedByString:@"','"]] UTF8String];
Upvotes: 9