Friday, March 16, 2012

Using joins in Query

void initParmDefault()
{
    Query                       query;
    QueryBuildDataSource        queryBuildDataSource,queryBuildDSProd;
    QueryBuildRange queryBuildRange,queryBuildRangeStatus;
    ;
    super();

    query = new Query();
    queryBuildDataSource = query.addDataSource(tablenum(InventTable));
    queryBuildDataSource.addSelectionField(fieldnum(InventTable, ItemId));
    queryBuildRange = queryBuildDataSource.addRange(fieldnum(InventTable, ItemType));
    queryBuildRange.value(SysQuery::value(ItemType::BOM));
    queryBuildRange.status(RangeStatus::Locked);
    queryBuildDataSource.addRange(fieldnum(InventTable, itemId));

    queryBuildDSProd = queryBuildDataSource.addDataSource(tablenum(ProdTable));
    queryBuildDSProd.addSelectionField(fieldnum(prodTable,itemId));
    queryBuildRangeStatus = queryBuildDSProd.addRange(fieldnum(ProdTable,ProdStatus));
    queryBuildRangeStatus.value(SysQuery::range(ProdStatus::Created,ProdStatus::StartedUp));
    queryBuildRangeStatus.status(RangeStatus::Locked);

    queryBuildDSProd.joinMode(JoinMode::ExistsJoin);
    queryBuildDSProd.fetchMode(QueryFetchMode::One2One);
    queryBuildDSProd.addLink(fieldnum(inventTable,itemid),fieldnum(prodTable,itemId));

    queryRun = new QueryRun(query);

    //QueryRun = new QueryRun(querystr(InventTable));


}