Object Queries

To retrieve data from a local database, use one of the static Object Query methods in the MBO class.

Object Query methods are generated based on the object queries defined by the modeler in Unwired WorkSpace. Object Query methods carry query name, parameters, and return type defined in Unwired WorkSpace. Object Query methods return either an object, or a collection of objects that match the specified search criteria.

The following examples demonstrate how to use the Object Query methods of the Customer MBO to retrieve data.

Consider an object query on a Customer MBO to find customers by last name. You can construct the query as follows:

Select  x.* from Customer x where x.lname =:param_lname

where param_lname is a string parameter that specifies the last name. Assume that the query above is named findBylname

This generates the following Client Object API:

(Customer *)findBylname : (NSString *)param_lname;

The above API can then be used just like any other read API. For example:

SampleApp_Customer * thecustomer = [ SampleApp_Customer findBylname: @”Delvin”];

For each object query that returns a list, additional methods are generated that allow the caller to select and sort the results. For example, consider an object query, findByCity, which returns a list of customers from the same city. Since the return type is a list ,the following methods would be generated. The additional methods help the user with ways to specify how many results rows to skip, and how many subsequent result rows to return.

+ (SUPObjectList*) findByCity:(NSString*) city;
+ (SUPObjectList*) findByCity:(NSString*) city skip;
(int32_t) skip take:(int32_t)take;

Supported Aggregate Functions

You can use aggregate functions including GroupBy in object queries. However, the sum, avg, and greater than (>) aggregate functions are not supported.

select count(x.id), x.id from AllType x where x.surrogatekey > :minSk group by x.id having
x.id < :maxId order by x.id