zoukankan      html  css  js  c++  java
  • Using query,queryRun

    As the name implies QueryRun is the executor of a query linked to it. To construct a query you want QueryRun to execute, you need build classes:

    Query
    QueryBuildDataSource
    QueryBuildRange
    QueryBuildFieldList
    QueryBuildLink
    QueryBuildDynaLink
     

    Today’s example will use the first four to demonstrate a query that sums the credit limit field in CustTable grouped by Country and Currency. Additionally a count field indicates how many records are represented in the sum. Ranges are implemented for AccountNum and Country, but the user is allowed to add additional range criteria in the dialog. To demonstrate the status() property I have locked it, so the user can not change it.

     

    QueryRun

    QueryRun executes the query. If needed the familiar query dialog can be opened before the query is run. This is done using the prompt() method. SysQueryRun extends QueryRun and has a total of 7 prompt*() methods, with different default behavior. For example promptAllowAddRange() would allow the user to add new where-conditions.

     

    Query

    A query represents the select statement. This is where all the strings come together.

     

    QueryBuildDataSource

    Using QueryBuildDataSources you add all the tables you want joined (just one in this example). This is also where you define how the resultset is to be sorted. The orderMode() method lets you define

    OrderBy
    GroupBy
     

    QueryBuildRange

    Ranges represent where conditions. Multiple ranges are connected with AND conditions. Unfortunately there is no easy way to change that.

     

    QueryBuildFieldList

    Represents the selected fields of the query. By default all fields are selected. In regular queries you probably wouldn’t use them that often, but when grouping this is the way to define which fields are calculated. SelectionField is an enum with the following values

     Avg
    Count
    Database
    Max
    Min
    Sum  
     

    The result of Test_Query on my test system looks something like this:

    CA CAD     1120,00 (3 records)

    CA USD      500,00 (1 records)

    DE EUR        0,00 (1 records)

    DK CAD     5000,00 (1 records)

    DK EUR      300,00 (6 records)

    DK GBP      560,00 (2 records)

    ES EUR        0,00 (1 records)

    IE EUR        0,00 (1 records)

    NL EUR       20,00 (2 records)

    NO EUR     3000,00 (1 records)

     

     

    static void Test_Query(Args _args)

    {

        CustTable            custTable;

        Query                query      = new Query();

        QueryRun             qr         = new queryRun(query);

        QueryBuildDataSource qbds       = qr.query().addDataSource(tableNum(CustTable));

        QueryBuildRange      qbrAccN    = qbds.addRange(fieldNum(CustTable,AccountNum));

        QueryBuildRange      qbrCountry = qbds.addRange(fieldNum(CustTable,Country));

        QueryBuildFieldList  qbfl       = qbds.fields();

        ;

     

        qbrAccN.value('4000..4050');

        qbrAccN.status(RangeStatus::Locked);

        qbrCountry.value('CA..NO');

     

        qbfl.addField(fieldNum(CustTable,CreditMax),SelectionField::Sum);

        qbfl.addField(fieldnum(CustTable,RecId),SelectionField::Count);

     

        qbds.addSortField(fieldnum(CustTable,Country));

        qbds.addSortField(fieldNum(CustTable,Currency));

        qbds.orderMode(OrderMode::GroupBy);

     

        if (qr.prompt())

        { 

            while (qr.next())

            {

                custTable = qr.get(tableNum(CustTable)); 

                print strfmt("%1 %2 %3 (%4 records)",custTable.Country,custTable.Currency,

                             num2str(custTable.CreditMax,10,2,0,0),custTable.RecId);

            } 

        } 

        pause;

    }

    From : http://axgeek.spaces.live.com/

  • 相关阅读:
    ASP.NET Zero--10.一个例子(3)商品分类管理-新建
    ASP.NET Zero--9.一个例子(2)商品分类管理-列表
    ASP.NET Zero--8.一个例子(1)菜单添加
    ASP.NET Zero--7.控制器加权限
    ASP.NET Zero--6.菜单加权限
    ASP.NET Zero--5.配置权限
    ASP.NET Zero--4.不使用谷歌字体,提升加载速度
    ASP.NET Zero--2.如何启动
    C# mongoDB Driver 使用对象方式最完善查询语法大全
    ef 数据库连接字符串加密
  • 原文地址:https://www.cnblogs.com/Fandyx/p/1812362.html
Copyright © 2011-2022 走看看