Dynamic Queries

Build queries based on user input.

Use the SUPQuery class to retrieve a list of MBOs.

  1. Specify the where condition used in the dynamic query.
    SUPQuery *myquery = [SUPQuery getInstance];
    myquery.testCriteria = [SUPAttributeTest match:@"fname" :@"Erin"];
  2. Use the findWithQuery method in the MBO to dynamically retrieve a list of MBOs acccording to the specified attributes.
    SUPObjectList* customers = [SampleAppCustomer findWithQuery:myquery]
  3. Use the generated database’s executeQuery method to query multiple MBOs through the use of joins.
    SUPQuery *query = [SUPQuery getInstance];
    [query select:@"c.fname,c.lname,s.order_date,s.id"];
    [query from:@"Customer":@"c"];
    [query join:@"SalesOrder":@"s":@"s.cust_id":@"c.id"];
    query.testCriteria = [SUPAttributeTest match:@"c.lname":@"Smith"];
    SUPQueryResultSet* resultSet = [SUP101_SUP101DB executeQuery:query];
    if(resultSet == nil)
    {
      MBOLog(@"executeQuery Failed !!");
      return;
    }
    for(SUPDataValueList* result in resultSet)
    {
      MBOLog(@"Firstname,lastname,order date,region = %@ %@ %@ %@",
      [SUPDataValue getNullableString:[result item:0]],
      [SUPDataValue getNullableString:[result item:1]],
      [[SUPDataValue getNullableDate:[result item:2]] description],
      [SUPDataValue getNullableString:[result item:3]]);
    }
Related concepts
Accessing MBO Data
Related reference
Query APIs