lingdanglfw(DAX)

导航

get record count of form datasource

modified class : SysQuery

 

public client server static Integer countTotal(QueryRun _queryRun,int num = 1)//add datasource num
{
    container c = SysQuery::countPrim(_queryRun.pack(false),num);

    return conpeek(c,1);
}

 

 

private server static container countPrim(container _queryPack,int num = 1)//add datasource num
{
    Query                   countQuery;
    QueryRun                countQueryRun;
    QueryBuildDataSource    qbds;
    QueryBuildFieldList     qbfl;
    Common                  common;
    Integer                 counter;
    Integer                 loops;
    ;
    countQueryRun   = new QueryRun(_queryPack);
    countQuery      = countQueryRun.query();
    qbds            = countQuery.dataSourceNo(num);//put datasource num
    qbds.update(false);
    qbds.sortClear();
    qbfl = qbds.fields();
    qbfl.dynamic(false);
    qbfl.clearFieldList();
    //if (countQuery.dataSourceCount() == 1)  //remark this
        qbds.addSelectionField(fieldnum(Common,RecId),SelectionField::Count);

    countQueryRun   = new QueryRun(countQuery);

    while (countQueryRun.next())
    {
        common  = countQueryRun.get(countQuery.dataSourceNo(num).table());//put datasource num
        counter += common.RecId;
        loops++;
    }

    return [counter,loops];
}

 

 

usage:

 

    Query query;
    QueryRun queryRun;
    ;
    query =new query();

    query.addDataSource(tablenum(CustTable)).addRange(fieldnum(CustTable,AccountNum)).value(queryRange('000001','000008'));


    queryRun = new QueryRun(query);
    info(strfmt('%1',SysQuery::countTotal(queryRun)));

 

 

 

 

 

posted on 2011-02-24 11:36  lingdanglfw  阅读(296)  评论(0编辑  收藏  举报