pochimen
pochimen

Reputation: 307

Sqlite IN Clause with NSArray

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

Answers (1)

Anusha Kottiyal
Anusha Kottiyal

Reputation: 3905

Change the query string to :

const char *sqlStatement =
[NSString stringWithFormat:@"select currencies from money where country IN ('%@')",[countries componentsJoinedByString:@"','"]] UTF8String];

Upvotes: 9

Related Questions