0

I need to construct a selectExpression for SimpleDB where I only want items with attributes = to X, sorted in descending order by attribute Y. All I have so far is this:

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

I would prefer to only select items (above) with attributes X by Y rather than get all items and then sort. How do I add this? Does it go in the selectExpression string or somewhere else. Many thanks!

Eric
  • 4,063
  • 2
  • 27
  • 49

2 Answers2

0
NSString *selectExpression = [NSString stringWithFormat:@"select itemName() from `%@` where X = '%@' order by 'X' descending",domainName,attributeValue];
Eric
  • 4,063
  • 2
  • 27
  • 49
  • The request above and in my question are right, the problem is the [items sort usingSelector] method. Take that out and it works. – Eric Sep 26 '11 at 13:08
0

Try this out --

Select x,y from <domain_name> where itemName() is not null order by itemName() asc 
Ashish Pancholi
  • 4,569
  • 13
  • 50
  • 88