从SimpleDB iPhone中选择count(*)

时间:2011-11-17 21:01:13

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

我想返回此域中的项目数。我知道count(*)返回一个名为Domain的项,其中包含一个名为Count的属性。我怎样才能获得伯爵的价值?

@try {
    SimpleDBSelectRequest  *selectRequest2  = [[SimpleDBSelectRequest alloc] initWithSelectExpression:@"select count(*) from %@"];
    SimpleDBSelectResponse *selectResponse = [[AmazonClientManager sdb] select:selectRequest2];

    for (SimpleDBItem *item in selectResponse.items) {
    if ( [item.name isEqualToString:@"Domain"])
    {
        NSLog(@"Attributes = %@",[item.attributes objectAtIndex:0]);
    }
    }
}
@catch (AmazonServiceException *exception) {
    NSLog(@"Exception = %@", exception);
}

我为属性获得了这个:

Attributes = {Name: Count,AlternateNameEncoding: (null),Value: 3,AlternateValueEncoding: (null),<SimpleDBAttribute: 0x8667120>}

如何从中获取价值3?

2 个答案:

答案 0 :(得分:1)

selectResponse应该有items属性,这是SimpleDBReplaceableAttribute个实例的可变数组。应该有一个name属性为“Count”且其value属性是计数的字符串表示形式。

这将是:

    SimpleDBReplaceableAttribute *attribute = [[selectResponse items] objectAtIndex:0];
    NSInteger count = [[attribute value] integerValue];

答案 1 :(得分:0)

这有效:

for (SimpleDBAttribute *attr in item.attributes) { if ([attr.name isEqualToString:@"Count"]) { int total = [attr.value intValue];