AWS SimpleDB Select Expression iPhone

时间:2011-09-20 20:30:08

标签: iphone nsmutablearray amazon-web-services amazon-simpledb

我需要为SimpleDB构造一个selectExpression,其中我只需要属性为to到X的项目,按属性Y的降序排序。到目前为止我所有的都是:

NSString *selectExpression = [NSString stringWithFormat:@"select itemName() from `%@`",domainString];

@try {
    SimpleDBSelectRequest  *selectRequest2  = [[[SimpleDBSelectRequest alloc] initWithSelectExpression:selectExpression] autorelease];
    SimpleDBSelectResponse *selectResponse = [[Constants sdb] select:selectRequest2];

    if (items == nil) {
        items = [[NSMutableArray alloc] initWithCapacity:[selectResponse.items count]];
    }
    else {
        [items removeAllObjects];
    }
    for (SimpleDBItem *item in selectResponse.items) {
        [items addObject:item.name];
    }
    [items sortUsingSelector:@selector(compare:)];
}
@catch (AmazonServiceException *exception) {
    NSLog(@"Exception = %@", exception);
}

我宁愿只选择属性为X的项目(上面),而不是获取所有项目然后排序。我该如何添加?它是否包含在selectExpression字符串中或其他位置。非常感谢!

2 个答案:

答案 0 :(得分:0)

NSString *selectExpression = [NSString stringWithFormat:@"select itemName() from `%@` where X = '%@' order by 'X' descending",domainName,attributeValue];

答案 1 :(得分:0)

试试这个 -

Select x,y from <domain_name> where itemName() is not null order by itemName() asc