ORDERY clause not working in simple db amazon in iphone application

56 views Asked by At

I am using ORDER BY clause to fetch data but it does not work in simple db amazon web service data base.if i do not use the order by clause in query then it works fine other wise it crashed the app.

below is the code.

select = [[NSString alloc] initWithFormat:@"select * FROM ContentMaster  where ContentAddedByUserID='%@' AND HiveletCode='%@' ORDER BY ContentAddedDateTime DESC",appDelegate.userID,appDelegate.organizationCode];

SimpleDBGetAttributesRequest *gar = [[SimpleDBGetAttributesRequest alloc] initWithDomainName:DOMAIN_NAME andItemName:itemNameUser];
SimpleDBGetAttributesResponse *response = [sdbClient getAttributes:gar];

NSString*nextToken;

NSLog(@" Catgeory ID is %@ ", appDelegate.categoryID);

NSLog(@"%@ ", appDelegate.organizationCode);
SimpleDBSelectRequest *selectRequest = [[[SimpleDBSelectRequest alloc] initWithSelectExpression:select] autorelease];

NSLog(@"Select Request is %@",selectRequest);

selectRequest.consistentRead = YES;
nextToken = selectRequest.nextToken;
NSLog(@"Next Token is %@",nextToken);

SimpleDBSelectResponse *selectResponse = [sdbClient select:selectRequest];
1

There are 1 answers

0
Bob Kinney On BEST ANSWER

From the SimpleDB documentation

The sort attribute must be present in at least one of the predicates of the expression.

This means you will probably need to change your query to:

select * FROM ContentMaster  where ContentAddedByUserID='%@' AND HiveletCode='%@' AND ContentAddedDateTime > 0 ORDER BY ContentAddedDateTime DESC

As for the crash, this an exception from the SDK, you should either disable exceptions and handle errors or put your calls in a @try/@catch block. You can read more about how exceptions and errors are handled in the AWS SDK for iOS in our blog.