Hi,
I want to create new queryrun with one new table based on existing queryrun.
If I have one datasource in base queryrun - all is OK.
If I have two datasources in base queryrun - nothing is OK :-(
Could anybody watch my example and tell me how can I change AddNewTable to see proper query ?
Regards
static void Job11A(Args _args)
{
Query Query;
QueryRun QueryRun;
QueryBuildDataSource qbds;
void AddNewTable(QueryRun _QueryRun)
{
QueryBuildDataSource qbdsCustTable;
QueryBuildDataSource qbdsAddress;
QueryRun LocalQueryRun;
Query LocalQuery;
boolean ret = true;
;
LocalQueryRun = new QueryRun(_QueryRun.query());
info (strfmt("# No changes: %1", LocalQueryRun.query().dataSourceNo(1).toString()));
//please help in this queryrun
LocalQuery = new query(_QueryRun.query());
qbdsCustTable = LocalQuery.dataSourceTable(tablenum(custTable));
qbdsAddress = qbdsCustTable.addDataSource(tablenum(Address));
qbdsAddress.relations(true);
qbdsAddress.fetchMode(QueryFetchMode::One2Many);
qbdsAddress.joinMode(joinMode::InnerJoin);
LocalQueryRun = new QueryRun(LocalQuery);
info (strfmt("# With changes: %1", LocalQueryRun.query().dataSourceNo(1).toString()));
}
;
info("Query with 1 datasource:");
Query = new Query();
qbds = Query.addDataSource(tablenum(custTable));
qbds.addRange(fieldnum(custTable, CustGroup)).value(queryValue("20"));
QueryRun = new QueryRun(Query);
AddNewTable(QueryRun);
info("Query with 2 datasources:");
Query = new Query();
qbds = Query.addDataSource(tablenum(custTable));
qbds.addRange(fieldnum(custTable, CustGroup)).value(queryValue("20"));
qbds = qbds.addDataSource(tablenum(custTrans)); //new line
qbds.relations(true); //new line
qbds.joinMode(joinMode::InnerJoin); //new line
QueryRun = new QueryRun(Query);
AddNewTable(QueryRun);
}
This is output:
Query with 1 datasource:
# No changes: SELECT FIRSTFAST * FROM CustTable WHERE ((CustGroup = N'20'))
# With changes: SELECT FIRSTFAST * FROM CustTable WHERE ((CustGroup = N'20')) JOIN FIRSTFAST * FROM Address WHERE CustTable.RecId = Address.AddrRecId AND CustTable.TableId = Address.AddrTableId
Query with 2 datasources:
# No changes: SELECT FIRSTFAST * FROM CustTable WHERE ((CustGroup = N'20')) JOIN FIRSTFAST * FROM CustTrans WHERE CustTable.AccountNum = CustTrans.AccountNum
# With changes: SELECT FIRSTFAST * FROM CustTable WHERE ((CustGroup = N'20')) (WHERE IS CustTrans and Address ???)
Expected output in query with 2 datsources:
SELECT FIRSTFAST * FROM CustTable WHERE ((CustGroup = N'20')) JOIN FIRSTFAST * FROM CustTrans WHERE CustTable.AccountNum = CustTrans.AccountNumJOIN FIRSTFAST * FROM Address WHERE CustTable.RecId = Address.AddrRecId AND CustTable.TableId = Address.AddrTableI
Regards