Sqlite IN子句与NSArray

poc*_*men 1 sqlite objective-c nsarray

我需要在Objective-C中使用带有NSArray的IN子句来执行Select语句.像这样的东西

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

....
Run Code Online (Sandbox Code Playgroud)

其中IN国家是带有字符串值的NSArray.这是真的吗?

Anu*_*yal 9

将查询字符串更改为:

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