ios - ORDER BY 子句在 iphone 应用程序的 simpledb amazon 中不起作用

标签 ios sql amazon-web-services sql-order-by amazon-simpledb

我正在使用 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];

最佳答案

来自SimpleDB documentation

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/

相关文章:

ios - 如何在协议(protocol)中声明泛型函数

sql - 使用 where 语句选择表中的所有内容...

node.js - 来自 Node.js 的 Amazon SNS 的 CERT_UNTRUSTED 错误响应

amazon-web-services - Alexa是 'Unable to Reach the Requested Skill'

perl - 如何使用 Perl SDK 在 Amazon Mechanical Turk 中使用 SetHITTypeNotification?

iphone - 使用 Phonegap 复制/粘贴剪贴板 iPhone

ios - 从 uicollectionciewcell 中的 uitextfield 更新和获取文本

ios - swift EXC_BAD_INSTRUCTION

mysql - 选择不同但按 24 小时分组?

mysql - SQL 按姓氏对具有重复元组的表进行分组