Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS -Windows Azure - MSTable - readWithQueryString

Tags:

ios

azure

How can I get some items from the table using queries? I use WindowsAzureMobileServices.framework (iOS app).

I will be very grateful If you can write some examples. I think it should be something like MySQL queries, but I can not create them correctly (always result = NULL, but the data is there).

self.authService = [AuthService getInstance];
MSTable *imagesTable = [self.authService.client tableWithName:@"images"];

[imagesTable readWithQueryString:@"" completion:^(NSArray *items, NSInteger totalCount, NSError *error) {
        NSLog(@"%@",items);
}];

Thank you

like image 273
user2561563 Avatar asked Dec 06 '25 00:12

user2561563


1 Answers

In Windows Azure Mobile Services, you can query in two ways: through the REST API or through a custom API.

Querying through the REST API:

The GET verb supports URI parameters conforming to the Open Data Protocol (OData). These parameters allow you to specify filters, order, projections, paging, and other features. The query is not based on SQL syntax, but in the OData syntax, which is tailored for entities served in the REST style.

This is documented in Query records operation and you'll find examples in the form of automated tests in the Mobile Services SDK for iOS: see MSQueryTests.m.

For instance, this sample code:

-(void)testMSQueryInitWithSimplePredicate
{    
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name == 'bob'"];

    query = [[MSQuery alloc] initWithTable:table predicate:predicate];
    STAssertTrue([query.description
                  isEqualToString:@"$filter=(name%20eq%20'bob')&$inlinecount=none"],
                 @"OData query string was: %@",
                 query.description);
}

There is also this example in How to use the iOS client library for Mobile Services:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"complete == NO"];
[table readWithPredicate:predicate completion:^(NSArray *items, NSInteger totalCount, NSError *error) {
    //loop through our results
}];

Querying through a custom API:

You can write your own functions that run on the server, take any arguments they need, execute any querying and processing they need, and return any result set. These functions are extremely flexible.

For information on how to develop these functions see Custom APIs in Azure Mobile Services.

To learn how to call these custom functions from iOS refer to Custom API in Azure Mobile Services – Client SDKs and also to this answer.

like image 85
Fernando Correia Avatar answered Dec 08 '25 13:12

Fernando Correia



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!