Openedge 8.3c动态查询

时间:2014-02-13 06:53:09

标签: progress-4gl openedge

如何在8.3c中执行动态查询?在V8.3c中我不能做的是拥有一个动态缓冲区,所以我可以像10.2b中的这些代码一样动态运行所有表。

DEFINE VARIABLE QueryHandler AS HANDLE    NO-UNDO.
DEFINE VARIABLE QueryBuffer  AS HANDLE    NO-UNDO.
DEFINE VARIABLE QueryString AS CHARACTER   NO-UNDO.
DEFINE VARIABLE BufferFields AS CHARACTER   NO-UNDO.
_TransactMain:
DO ON ERROR UNDO, LEAVE:
    CREATE QUERY QueryHandler.
    _TableLoop:
    FOR EACH ttTableFields NO-LOCK /* filtered System Table */
        BREAK BY tablename:

        IF FIRST-OF(tablename) THEN DO:
            ASSIGN
                QueryString = "For each " + TableFields.TableName + ":"
                BufferFields = "".
        END.
            /* Delimited Fields */
            /* Loop through fields -1 to avoid null at end */
            ASSIGN
                BufferFields = TableFields.FieldName + ";" + BufferFields.

        IF LAST-OF(TableName) THEN DO:
            /* Create Buffer to selected group of fields */
            CREATE BUFFER QueryBuffer FOR TABLE TableFields.TableName NO-ERROR.
            IF ERROR-STATUS:ERROR = TRUE THEN DO:
                NEXT _TableLoop.
            END.
            /* Set this as current buffer handled by Query */
            QueryHandler:SET-BUFFERS(QueryBuffer) NO-ERROR.
            IF ERROR-STATUS:ERROR = TRUE THEN DO:
                NEXT _TableLoop.
            END.
            /* Prepare query string and also check if correct syntax */
            QueryHandler:QUERY-PREPARE(QueryString) NO-ERROR.
            IF ERROR-STATUS:ERROR = TRUE THEN DO:
                NEXT _TableLoop.
            END.
            /* Execute Query and Check if valid query*/
            QueryHandler:QUERY-OPEN() NO-ERROR.
            IF ERROR-STATUS:ERROR = TRUE THEN DO:
                NEXT _TableLoop.
            END.
            ELSE DO: /* If all above are correct */
                IF QueryHandler:GET-FIRST(NO-LOCK) = TRUE THEN DO:
                    RUN DoReplace(BufferFields).
                END.
                ELSE DO:
                    NEXT _TableLoop.
                END.
            END.
        END.
    END.
END.

这是我的DoReplace程序:

DEFINE INPUT PARAMETER chkFields AS CHARACTER NO-UNDO.
DEFINE VARIABLE i AS INTEGER     NO-UNDO.

DO WHILE queryBuffer:AVAILABLE:
    DO TRANSACTION i = 1 TO NUM-ENTRIES(chkFields,";") - 1:
        /* Code Incomplete */
        queryBuffer:BUFFER-FIELD(ENTRY(i,chkFields,";")):BUFFER-VALUE.
    END.
    QueryHandler:GET-CURRENT(NO-LOCK).
    QueryHandler:GET-NEXT(NO-LOCK).
END.

这些代码在v8.3c中无法运行,因为它不支持动态查询。 我在v8.3c中找不到解决方法。

2 个答案:

答案 0 :(得分:2)

动态查询直到9.0才可用,所以你的8. *应用程序运气不好。

答案 1 :(得分:1)

版本8当然是史前的。

在版本8及更早版本中,您将通过“即时编译”(需要编译器许可证)来实现此类事情。

类似的东西:

/* q.p
 */

for each {1} no-lock {2}:
  display {3}.
end.

然后你调用传递你的变量位作为参数,如下所示:

run q.p "customer" "where customer.state = 'ma'" "name".

这比v9 +动态查询要困难得多,并且编译器要求会阻止很多用途,但对于你正在做的事情来说它可能已经足够了。