Reputation: 35
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.
Upvotes: 1
Views: 1423
Reputation: 14020
Version 8 is, of course, prehistoric.
In version 8 and earlier you would implement this sort of thing via "compile on the fly" (which requires a compiler license).
Something like:
/* q.p
*/
for each {1} no-lock {2}:
display {3}.
end.
Which you then call passing your variable bits as arguments like so:
run q.p "customer" "where customer.state = 'ma'" "name".
This is much cruder than v9+ dynamic queries and the compiler requirement prevents a lot of uses but it might be good enough for whatever it is that you are doing.
Upvotes: 1
Reputation: 3251
Dynamic queries didn't become available until 9.0, so your 8.* application is out of luck.
Upvotes: 2