1

我需要在 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];

....

其中 IN countries 是带有字符串值的 NSArray。这可能吗?

4

1 回答 1

9

将查询字符串更改为:

const char *sqlStatement =
[NSString stringWithFormat:@"select currencies from money where country IN ('%@')",[countries componentsJoinedByString:@"','"]] UTF8String];
于 2012-12-13T04:17:34.750 回答