0

I want to return the count of items in this domain. I know count (*) returns one item called Domain with an attribute called Count. How do I get Count's value?

@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);
}

I get this for Attributes:

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

How do I get the Value 3 out of it?

Eric
  • 4,063
  • 2
  • 27
  • 49
  • Does the code in the answer not work? It should go just after, or in place of the `NSLog(@"Attributes...")` statement – FluffulousChimp Nov 17 '11 at 22:04
  • This worked:for (SimpleDBAttribute *attr in item.attributes) { if ([attr.name isEqualToString:@"Count"]) { int total = [attr.value intValue]; – Eric Nov 17 '11 at 22:29

2 Answers2

1

The selectResponse should have an items property which is a mutable array of SimpleDBReplaceableAttribute instances. There should be one whose name property is "Count" and whose value property is a string representation of the count.

It would be something like:

    SimpleDBReplaceableAttribute *attribute = [[selectResponse items] objectAtIndex:0];
    NSInteger count = [[attribute value] integerValue];
FluffulousChimp
  • 9,157
  • 3
  • 35
  • 42
0

This worked:

for (SimpleDBAttribute *attr in item.attributes) { if ([attr.name isEqualToString:@"Count"]) { int total = [attr.value intValue];
Eric
  • 4,063
  • 2
  • 27
  • 49