我正在使用 ORDER BY
子句来获取数据,但它在简单的 db 亚马逊 Web 服务数据库中不起作用。如果我不在查询中使用 order by 子句,那么它在其他方面也能正常工作它使应用程序崩溃。
下面是代码。
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];
最佳答案
The sort attribute must be present in at least one of the predicates of the expression.
这意味着您可能需要将查询更改为:
select * FROM ContentMaster where ContentAddedByUserID='%@' AND HiveletCode='%@' AND ContentAddedDateTime > 0 ORDER BY ContentAddedDateTime DESC
至于崩溃,这是 SDK 的异常,您应该禁用异常并处理错误,或者将您的调用放在 @try/@catch block 中。您可以在 our blog 中阅读更多关于如何在适用于 iOS 的 AWS 开发工具包中处理异常和错误的信息。 .
关于ios - ORDER BY 子句在 iphone 应用程序的 simpledb amazon 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20515706/