AWS SimpleDB 的默认结果限制为 100,我正在尝试从我的数据库中获取最后 20 条记录。他们的在线帮助指出:“count(*) 和 select 返回的下一个标记是可以互换的,只要 where 和 order by 子句匹配即可。例如,如果您想返回前 10,000 项之后的 200 项(类似于偏移量) ),您可以使用 10,000 的限制子句执行计数,并使用下一个标记通过 select 返回接下来的 200 个项目。”
所以我试图弄清楚如何执行这两个操作。我首先计算记录数(在我的示例中约为 160),然后从中减去 20 以创建偏移量。但 AWS 仍在返回前 100 条记录。我认为“//++”之间的代码在创建偏移量时不正确。
//++ AWS has display limit of 100 so create offset by starting from count - 20
NSString *sdbAppOffset = [NSString stringWithFormat:@"select count(*) from %@ limit %i",sdbAppUse,iDbaseRecordCountOffset];
SimpleDBSelectRequest *selectOffsetRequest = [[SimpleDBSelectRequest alloc] initWithSelectExpression:sdbAppOffset];
selectOffsetRequest.consistentRead = YES;
SimpleDBSelectResponse *selectOffSetResponse = [sdbClient select:selectOffsetRequest];
//NSLog(@"sdbAppUse count %i",[selectOffSetResponse.items count]);
//++
NSString *sdbAppUseString = [NSString stringWithFormat:@"select * from %@",sdbAppUse];
SimpleDBSelectRequest *selectRequest = [[SimpleDBSelectRequest alloc] initWithSelectExpression:sdbAppUseString];
selectRequest.consistentRead = YES;
SimpleDBSelectResponse *selectResponse = [sdbClient select:selectRequest];
NSLog(@"sdbAppUse count %i",[selectResponse.items count]);
for (int x = 0; x < [selectResponse.items count]; x++) {
SimpleDBItem *registerUser = [selectResponse.items objectAtIndex:x];
for (SimpleDBAttribute *attribute in registerUser.attributes) {
NSLog(@"trackUsage registerUser |%@|, name |%@|, value |%@|",registerUser.name, attribute.name, attribute.value);
}
}