Вопрос

Good Day,

I am trying to select an item on SimpleDB using the iOS SDK. The issue is the only way I know how to do it is to use SimpleDBGetAttributesRequest to get the item name, then check the date attribute and see if it matches the one i requested.

This is definitely a horrible way to do it as I have to keep querying the entire database just for this. Is there an easy way to check the attributes rather than the name, or a way to select date?

Это было полезно?

Решение 2

I have written a simple piece of code as such with your above solution

-(void)RunQuery:(NSString*)query{
NSLog(@"Running Query\n");
NSString* selectExpression=query;
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(queue, ^{
    dispatch_async(dispatch_get_main_queue(), ^{
        [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
    });
    @try {
        //Code start
        SimpleDBSelectRequest *selectRequest = [[SimpleDBSelectRequest alloc] initWithSelectExpression:selectExpression];
        selectRequest.consistentRead = YES;

        SimpleDBSelectResponse *selectResponse = [sdbClient select:selectRequest];

        for (SimpleDBItem *item in selectResponse.items) {
            NSLog(@"%@",item.name);
        }
        //Code end
    }
    @catch (AmazonServiceException *exception) {
        NSLog(@"Exception = %@", exception);
    }
    dispatch_async(dispatch_get_main_queue(), ^{
        [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
    });
});
}

Другие советы

I'm not an iOS SDK expert, but sounds like SimpleDBSelectRequest would work for you with a selectExpression like :

select * from your_domain where your_date = '1970-01-01'

if you know the date, or:

select * from your_domain where your_date between '1970-01-01' and '1970-01-05'

if you only know the date range.

Remember that SimpleDB treats dates like strings, so format your dates appropriately in your query to match the way you are storing them.

-Larry

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top