Openedge 8.3c Dynamic Query

Status
Not open for further replies.
I

Iojecht

Guest
How will I able to do Dynamic Query in 8.3c? What I can't do in V8.3c is to have a dynamic buffer so I can run all the tables dynamically like these code in 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.


Here is my DoReplace Procedure:


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.


These code can't work in v8.3c because it doesn't support for dynamic query. I can't find a workaround in v8.3c.

Continue reading...
 
Status
Not open for further replies.
Top