OpenEdge中的动态查询

时间:2017-08-23 06:28:39

标签: openedge progress-4gl dynamicquery

美好的一天:

快速提问:我可以在OpenEdge中执行动态查询吗?

示例:

def temp-table tt-num1
field f1 as int
field f2 as int.

def temp-table tt-num2
field f1 as int
field f2 as int.

def temp-table tt-num3
field f1 as int
field f2 as int.

我需要的是这样的东西:

procedure repeat-query:
for each 'variable that contains table-name' no-lock.

disp f1 f2.

end.
end procedure.

或其他可以解决我问题的方法。

我该如何处理?我试图在互联网上检查动态查询,但没有运气。提前谢谢。

1 个答案:

答案 0 :(得分:4)

如果直接转到https://documentation.progress.com/#page/progdocindex%2Fopenedge.html,您可以找到有关OpenEdge所有内容的文档。例如动态查询。

我并不完全明白您尝试做什么,但这里是动态查询的示例。

DEFINE TEMP-TABLE tt-num1 NO-UNDO
    FIELD f1 AS INTEGER
    FIELD f2 AS INTEGER.

DEFINE TEMP-TABLE tt-num2 NO-UNDO
    FIELD f1 AS INTEGER
    FIELD f2 AS INTEGER.

DEFINE TEMP-TABLE tt-num3 NO-UNDO
    FIELD f1 AS INTEGER
    FIELD f2 AS INTEGER.


CREATE tt-num1.
ASSIGN 
    tt-num1.f1 = 1
    tt-num1.f2 = 1.

CREATE tt-num1.
ASSIGN 
    tt-num1.f1 = 1
    tt-num1.f2 = 2.

CREATE tt-num1.
ASSIGN 
    tt-num1.f1 = 2
    tt-num1.f2 = 1.

CREATE tt-num1.
ASSIGN 
    tt-num1.f1 = 2
    tt-num1.f2 = 2.

DEFINE VARIABLE hQuery  AS HANDLE      NO-UNDO.
DEFINE VARIABLE cBuffer AS CHARACTER   NO-UNDO.
DEFINE VARIABLE cField  AS CHARACTER   NO-UNDO.
DEFINE VARIABLE iValue  AS INTEGER     NO-UNDO.

ASSIGN 
    cBuffer = "tt-num1"
    cField  = "f1"
    iValue  = 1.

CREATE QUERY hQuery.

hQuery:ADD-BUFFER(cBuffer).
hQuery:QUERY-PREPARE("for each " + cBuffer + " where " + cBuffer + "." + cField + " = " + STRING(iValue)).
hQuery:QUERY-OPEN().

queryLoop:
REPEAT:
    hQuery:GET-NEXT().

    IF hQuery:QUERY-OFF-END THEN LEAVE queryLoop.

    DISPLAY hQuery:GET-BUFFER-HANDLE(1):BUFFER-FIELD(cField):BUFFER-VALUE.
END.
hQuery:QUERY-CLOSE().

DELETE OBJECT hQuery.

正如Stefan Drissen在一个非常有效的评论中提到的:循环可以更紧凑:

DO WHILE hQuery:GET-NEXT():
    /* Code goes here */
END.