如何使用prodataset进行4GL实现5表的连接?

时间:2013-10-29 08:24:50

标签: progress-4gl openedge

我有5个与父子关系相关的表。像table1 - > table2-> table3-> table4-> table5,此处箭头显示父对子关系。如何使用prodataset in progress 4GL从这些相关表中获取记录? 我该如何为这种情况定义查询?

1 个答案:

答案 0 :(得分:0)

这是一个连接了1个表的示例,只需使用FIRST格式向cQuery添加更多表。

    ASSIGN
      cQuery = "FOR EACH table1 NO-LOCK ":U
             + "   WHERE table1.product_obj = ":U + QUOTER(cProduct)
             + "     AND table1.role_obj    = ":U + QUOTER(cRole)
             + "  ,FIRST table2 NO-LOCK ":U
             + "   WHERE table2.criterion_obj = table1.criterion_obj":U.

    hQuery:SET-BUFFERS(BUFFER table1:HANDLE, BUFFER table2:HANDLE).

    hQuery:QUERY-PREPARE(cQuery) NO-ERROR.
    hQuery:QUERY-OPEN() NO-ERROR.
    hQuery:GET-FIRST() NO-ERROR.

    DO  WHILE NOT hQuery:QUERY-OFF-END:
        <put logic here>
        hQuery:GET-NEXT() NO-ERROR.
    END.

============

对于ProDataSet,您需要定义临时表 然后创建ProDataSets

手册中的示例:

DEFINE TEMP-TABLE ttOrder LIKE Order
    FIELD OrderTotal AS DECIMAL
    FIELD CustName LIKE Customer.NAME
    FIELD RepName LIKE SalesRep.RepName.

DEFINE TEMP-TABLE ttOline LIKE OrderLine.

DEFINE TEMP-TABLE ttItem
    FIELD ItemNum LIKE ITEM.ItemNum
    FIELD ItemName LIKE ITEM.ItemName
    FIELD Price LIKE ITEM.Price
    FIELD Weight LIKE ITEM.Weight
    FIELD OnHand LIKE ITEM.OnHand
    FIELD OnOrder LIKE ITEM.OnOrder.

DEFINE DATASET dsOrder FOR ttOrder, ttOline, ttItem
DATA-RELATION OrderLine FOR ttOrder, ttOline
RELATION-FIELDS (OrderNum, OrderNum)
DATA-RELATION LineItem FOR ttOline, ttItem
RELATION-FIELDS (ItemNum, ItemNum).

DEFINE VARIABLE hDSOrder AS HANDLE NO-UNDO.
hDSOrder = DATASET dsOrder:HANDLE.

DEFINE QUERY qOrder FOR Order, Customer, SalesRep.
DEFINE QUERY qItem FOR ITEM.
DEFINE DATA-SOURCE srcOrder FOR QUERY qOrder
Order KEYS (OrderNum), Customer KEYS (CustNum), SalesRep KEYS (SalesRep).
DEFINE DATA-SOURCE srcOline FOR OrderLine.
DEFINE DATA-SOURCE srcItem FOR QUERY qItem ITEM KEYS (ItemNum).

BUFFER ttOrder:ATTACH-DATA-SOURCE(DATA-SOURCE srcOrder:HANDLE,
"Customer.Name,CustName").
BUFFER ttOline:ATTACH-DATA-SOURCE(DATA-SOURCE srcOline:HANDLE).
BUFFER ttItem:ATTACH-DATA-SOURCE(DATA-SOURCE srcItem:HANDLE).

QUERY qOrder:QUERY-PREPARE("FOR EACH Order WHERE Order.OrderNum = 1, " +
    "FIRST Customer OF Order, FIRST SalesRep OF Order"). /* setup query to fill 
     dataset */

hDSOrder:FILL(). /* fill the ProDataSet as a whole */